gpt4 book ai didi

Azure bash CLI 支持 while 和 do

转载 作者:行者123 更新时间:2023-12-03 04:50:42 25 4
gpt4 key购买 nike

我正在尝试编写一个 bash 脚本来解析传递给脚本的参数:

while [[ $# -gt 0 ]]
do
case $1 in
-n|--name)
VMNAME="$2"
shift
shift
;;
-a|--admin-user)
ADMINUSERNAME="$2"
shift
shift
;;
-l|--location)
LOCATION="$2"
shift
shift
;;
-g|-resource-group)
RESOURCEGROUPNAME="$2"
shift
shift
;;
-a|--availability-set)
AVAILABILITYSETNAME="$2"
shift
shift
;;
*) # unknown option
echo unknwon "$1"
shift # past argument
;;
esac
done

echo "vn name = "
echo $VMNAME
echo "Admin User = " $ADMINUSERNAME
echo "Location = " $LOCATION
echo "Resource Group = " $RESOURCEGROUPNAME
echo "Availability Set = " $AVAILABILITYSETNAME

如果我 ssh 进入 Linux 虚拟机并运行脚本,效果很好。如果我尝试从 Azure CLI 执行脚本,则会收到以下错误:

myaccount@Azure:~/clouddrive$ bash test.bash -n test
test.bash: line 1: syntax error in conditional expression
'est.bash: line 1: syntax error near `]]
'est.bash: line 1: `while [[ $# -gt 0 ]]

Azure CLI 在编程语言支持方面与 Linux bash shell 有何不同? Azure bash CLI 支持哪种编程结构和流控制?

最佳答案

我在实验室进行测试并重现您的错误:

enter image description here

我们应该将 Windows (CR LF) 更改为 Unix (LF),然后上传到此 shell。

enter image description here

关于Azure bash CLI 支持 while 和 do,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46436351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com