1
我自己对无法找到这样看似微不足道的事情表示歉意。从shell脚本命令行读取布尔参数的“无约束变量”
我需要通过多于一个的布尔参数到外壳脚本(击)如下:
./script --parameter1 --parameter2
等。
如果设置,所有都被认为是true
。
在脚本的开头,我用set -u
。
与价值传递我目前做的正常参数如下:
# this script accepts the following arguments:
# 1. mode
# 2. window
while [[ $# > 1 ]]
do
cmdline_argument="$1"
case $cmdline_argument in
-m|--mode)
mode="$2"
shift
;;
-w|--window)
window="$2"
shift
;;
esac
shift
done
我想补充像
-r|--repeat)
repeat=true
shift
;;
我不明白为什么它无法正常工作预期。
它有错误立即退出:
./empire: line 450: repeat: unbound variable
当行450:
if [ "$repeat" == true ];
你能澄清它是如何失败吗?是因为你错过了一个“转变”吗? –
@GordonDavisson我试过了,没有“shift”。 – Vlastimil
你正在使用'set -u',对吗? –