You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure App Service Kudu Shell下通过Bash创建applicationHost.xdt文件报错

问题根因

你遇到的报错是Azure Kudu环境的shell对双引号内转义字符的解析规则和本地标准bash/zsh不一致导致的:你原有命令里用\"转义双引号的写法没有被Kudu shell正确识别,导致包裹字符串的双引号提前闭合,后续内容里的<被shell当成了输入重定向符,系统尝试读取名为?xml的不存在的文件,就抛出了对应的No such file or directory报错。

解决方法

优先推荐用Here Document的方式一次性写入文件,不需要处理复杂的转义规则,也不用拼接多段echo命令,稳定性更高:

cat > applicationHost.xdt << 'EOF'
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> 
  <system.webServer>
    <runtime xdt:Transform="InsertIfMissing">
      <environmentVariables xdt:Transform="InsertIfMissing">
        <add name="FOO" value="BAR" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
        <add name="PATH" value="%PATH%;%HOME%\BAR" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
      </environmentVariables>
    </runtime>
  </system.webServer>
</configuration>
EOF

<< 'EOF'用单引号包裹标记符后,中间所有内容都会原样输出,不会解析变量、转义字符,完全匹配你需要生成的xml文件内容。

如果要沿用原有echo链式命令的写法,把所有包裹内容的双引号替换为单引号即可,单引号内的双引号不需要额外转义,就能被正确识别:

echo '<?xml version="1.0"?>' > applicationHost.xdt && echo '<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> ' >> applicationHost.xdt && echo '  <system.webServer>' >> applicationHost.xdt && echo '    <runtime xdt:Transform="InsertIfMissing">' >> applicationHost.xdt && echo '      <environmentVariables xdt:Transform="InsertIfMissing">' >> applicationHost.xdt && echo '        <add name="FOO" value="BAR" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />' >> applicationHost.xdt && echo '        <add name="PATH" value="%PATH%;%HOME%\BAR" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />' >> applicationHost.xdt && echo '      </environmentVariables>' >> applicationHost.xdt && echo '    </runtime>' >> applicationHost.xdt && echo '  </system.webServer>' >> applicationHost.xdt && echo '</configuration>' >> applicationHost.xdt

验证方法

文件生成后执行cat applicationHost.xdt查看输出内容,确认xml结构和字符完全符合预期后,重启Azure App Service即可生效。

内容的提问来源于stack exchange,提问作者munkaboo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.10 11:12:03