无法设置变量case语句庆典 [英] unable to set variable in case statement bash
本文介绍了无法设置变量case语句庆典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想设置的基础上一堆的输入条件的变量。这里的code的小样本:
#!/斌/庆典
INSTANCE_SIZE =
案$ 1
微)
$ INSTANCE_SIZE =t1.micro
;;
小)
$ INSTANCE_SIZE =的m1.small ;;
ESAC
回声$ INSTANCE_SIZE
当我运行与-ex开关脚本,并指定适当的参数:
+案例$ 1
+ =的m1.small
./provision:第19行:=的m1.small:命令未找到
解决方案
您需要删除该任务的 $
标志 - INSTANCE_SIZE =的m1.small
。随着美元符号, $ INSTANCE_SIZE
被其取代的价值,也没有转让发生 - bash而尝试执行是由于插值命令
I'm trying to set a variable based on a bunch of input conditions. Here's a small sample of the code:
#!/bin/bash
INSTANCE_SIZE=""
case "$1" in
"micro")
$INSTANCE_SIZE="t1.micro"
;;
"small")
$INSTANCE_SIZE="m1.small"
;;
esac
echo $INSTANCE_SIZE
When I run the script with the -ex switch and specify the proper argument:
+ case "$1" in
+ =m1.small
./provision: line 19: =m1.small: command not found
解决方案
You need to remove the $
sign in the assignments - INSTANCE_SIZE="m1.small"
. With the dollar sign, $INSTANCE_SIZE
gets substituted with its value and no assignment takes place - bash rather tries to execute the command that resulted from the interpolation.
这篇关于无法设置变量case语句庆典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文