- 论坛徽章:
- 0
|
要说getopts有bug根本就不可能! 但下面的现象让我难以理解, 谁能解释下? 还是我自己有啥问题?
$ cat test.sh
while getopts ':a:b:' opt
do
case $opt in
a)echo $OPTARG
;;
b)echo $OPTARG
;;
print "ERROR: an argument required following -$OPTARG option."
;;
\?)
print "invalid option --$OPTARG"
;;
esac
done
执行看结果:
$ ./test.sh -a
ERROR: an argument required following -a option. ===> 结果符合预期
$ ./test.sh -b
ERROR: an argument required following -b option. ===>结果符合预期
$ ./test.sh -a -b ===>结果令人困惑
-b
对 ./test.sh -a -b 的预期结果是:
ERROR: an argument required following -a option.
ERROR: an argument required following -b option
但在这个例子中, -b显然被当作了option -a的参数 ...但-b应该被识别为另一个独立的option啊 .... what is wrong?? |
|