getopt不接受以连字符开头的参数值- [英] getopt not accepting argument value starting with hyphen -
本文介绍了getopt不接受以连字符开头的参数值-的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的脚本具有选项o
,该选项应接受参数作为值,如下所示
My script has an option o
, which should accept argument as value, as below
./script -o '-p 2' ls
但是getopt不允许,给出错误
but getopt is not allowing, giving an error
Unrecognized option '-p 2'
代码段:
ARGS=$(getopt -a -n $0 -o o::h -- "$@")
eval set -- "$ARGS"
while true
do
case "$1" in
-o) opt="$2"; echo "options: $2"; shift; shift;;
-h) echo "$usage"; exit 0;;
--) cmd="$2"; shift; break;;
esac
done
如何将参数作为值传递给脚本?
How can I pass arguments as value to script?
推荐答案
您应在
这篇关于getopt不接受以连字符开头的参数值-的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文