传递键=值时,az管道嵌入的“&”号中断

问题描述

如何传递包含&符和其他字符的值。以下Powershell脚本失败

 $groupname = "owtest"
 $tags = @()
 $key="test"
 $value="some=&this&that"
 $tags += "$key=$value"
 $creation = az pipelines variable-group create --name $groupname --variables $tags --only-show-errors

是否存在允许“&”号嵌入字符的解决方法

解决方法

在我的测试中,对于包含&或其他字符的值,我们必须使用双引号单引号无法在这种情况下使用)。因此,如果您将变量直接传递给最终命令,则应为:

az pipelines variable-group create --name $groupname --variables test="some=&this&that" ...

如果要使用上述格式($tags += "$key=$value"),则需要 使用$value="""some=&this&that"""代替$value="some=&this&that"

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...