shell编程中的一些坑

来源:互联网 发布:最终信仰知轩 编辑:程序博客网 时间:2024/04/26 07:40

1、在用getopt接受选项和参数的时候

set -- $(getopt ab:cd $@)while [ -n $1 ]do case $1 in -a);; -b);; esac echo $1 shiftdone

这个代码根本停不下,根据检查发现在检查变量$1是不是为空的时候,一直是不为空的。在这个判断的时候一定要在变量上加上双引号。

set -- $(getopt ab:cd $@)while [ -n "$1" ]do case $1 in -a);; -b);; esac echo $1 shiftdone