Azure NSG规则创建时通配符*解析失败问题求助
解决Azure Cloud Shell中NSG规则命令通配符*解析问题
问题根源是Bash等Shell会对未加引号的*执行路径扩展,将其替换为当前目录下的所有非隐藏文件名,导致Azure CLI接收到的不是预期的*字符串。
以下两种方案可以解决:
方案一:赋值时用单引号包裹通配符
直接在变量赋值阶段用单引号保留*的字面量,避免Shell提前解析:DPortRange='*' az network nsg rule create -g $ResourceGroup --nsg-name $NSG -n $RULENAME --priority 100 \ --destination-address-prefixes $Destination --destination-port-ranges $DPortRange --direction \ inbound --access Allow --protocol TCP方案二:引用变量时用双引号包裹
如果变量已经赋值,在传递给Azure CLI时用双引号包裹变量,阻止Shell对变量内容进行通配符扩展:DPortRange=* az network nsg rule create -g $ResourceGroup --nsg-name $NSG -n $RULENAME --priority 100 \ --destination-address-prefixes $Destination --destination-port-ranges "$DPortRange" --direction \ inbound --access Allow --protocol TCP
这两种方法都能确保Azure CLI接收到的是字面量*,和直接指定--destination-port-ranges '*'的效果一致。
内容的提问来源于stack exchange,提问作者VorX
相关产品推荐
相关产品推荐

