【发布时间】:2014-10-10 07:36:43
【问题描述】:
我意识到 shift 将 cli args n 空间的数组向左移动,并且 n 的默认值为 1。这意味着我可以在 while 循环中使用 $1 shift 将数组的值分配给现有变量。我不太明白为什么在下面的上下文中使用它。输入参数已分配给值,删除 shift $((OPTIND-1)) 不会改变这一事实。来源:http://linux.die.net/man/3/optind
while getopts ":h:a:fc" opt; do
case $opt in
h)
print_help
exit 0
;;
a)
aaaa=${OPTARG}
;;
f)
force=1
;;
c)
CLEAN=1
;;
\?)
echoerr "Invalid option -$OPTARG"
print_help
exit 1
;;
esac
done
shift $((OPTIND-1))
【问题讨论】:
-
如果还有位置参数呢?
标签: bash