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

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 21:21:45