如何发送包含&号的Azure应用程序配置值?



我正在使用Azure CLI尝试将应用程序配置值设置为此URL:

az appconfig kv set --key "mykey" --value "https://fake.com/action?param1=a&param2=b" -n "test" --yes

得到以下结果。注意,这是来自az命令,而不是来自shell。

Please specify config store name or connection string(suggested).
'param2' is not recognized as an internal or external command,
operable program or batch file.

有没有办法让az把这个URL作为值,而不必诉诸愚蠢的东西,如URL编码它?我觉得这个坏了。

还请注意,消息Please specify config store name or connection string(suggested).是因为它无法正确解析命令行,因为这是用-n指定的。如果我移动参数:

az appconfig kv set -n "test" --yes --key "mykey" --value "https://fake.com/action?param1=a&param2=b"

我现在得到这个:

{
"contentType": null,
"etag": "zuspBqPBOHR1mXfcKCgORXHpAxB",
"key": "mykey",
"label": null,
"lastModified": "2021-08-31T17:39:14+00:00",
"locked": false,
"tags": {},
"value": "https://fake.com/action?param1=a"
}
'param2' is not recognized as an internal or external command,
operable program or batch file.

看起来更糟。它错误地创建了键值对,然后试图将param2作为命令运行。WTF ?

@d-m的链接让我看到了这个:

https://github.com/Azure/azure-cli/blob/dev/doc/quoting-issues-with-powershell.md

该链接完全解释了它,但基本上我需要在单引号内使用双引号,因为Powershell计算参数,然后cmd计算它们。因此,powershell会去掉单引号,然后cmd会去掉双引号,最后az会得到正确的参数。

如此:

az appconfig kv set -n "test" --yes --key "mykey" --value '"https://fake.com/action?param1=a&param2=b"'
{
"contentType": "text/plain",
"etag": "XugiNgxa2I04w0gaG2OBh9Jcj75",
"key": "mykey",
"label": null,
"lastModified": "2021-08-31T18:20:44+00:00",
"locked": false,
"tags": {},
"value": "https://fake.com/action?param1=a&param2=b"
}

<代码>

Azure CLI默认使用Bash。

"foo&bar"是Bash中的一个特殊字符,必须转义。

根据这个答案,您可以直接使用反斜杠:'foo&bar'或将整个参数用单引号括起来:`.

从PowerShell发出这两个命令应该没有问题,因为PowerShell使用反引号(CC_8)来转义其特殊字符。

相关内容

最新更新