【发布时间】:2012-10-02 12:26:07
【问题描述】:
这是获取和设置 OPTS 的正确方法吗?
我希望能够接受很多选择,例如
./runthis.sh --option1 setuff --option2 setmorestuff
while :
do
case $1 in
-h | --help | -\?)
usage
exit 0
;;
-o | --option1)
O=$2
shift 2
;;
-z | --option2)
Z=$2
shift 2
;;
--) # End of all options
shift
break
;;
-*)
echo "WARN: Unknown option (ignored): $1" >&2
shift
;;
*) # no more options. Stop while loop
break
;;
esac
done
【问题讨论】:
-
while :本质上与while true相同。
标签: linux bash shell command-line getopts