我想使用getoptsparsing一些bash脚本的参数,但希望能够访问未包含在选项列表中的剩余参数。 举个例子,如果我有一个电话:
% script -a -b param -c param -d other arguments here
我会:
while getopts "ab:c:d" opt ; do . done
获得“其他论点”的最简单的方法是什么?它应该由getopts来处理?
当你parsing一个arg时,你需要移动,或者放
在完成parsing之后转换$((OPTIND -1)),然后按照通常的方式处理
while getopts "ab:c:d" opt ; do . done shift $(expr $OPTIND - 1 ) while test $# -gt 0; do echo $1 shift done