小编use*_*ser的帖子

无法识别的选项错误:shell 中的 getopt 命令

我是 shell 和 Linux 的新手,如果有人能帮助我找出命令中的错误,那就太好了:

if ! options=$(getopt -n myscript -l a:,b:,cc:,dd:,ee:,ff:,gg:,hh: -- "$@"); then exit 1; fi
Run Code Online (Sandbox Code Playgroud)

我收到一条错误消息:

mhagent: unrecognized option '--hh'
options=' --aa '\''val1'\'' --ibb '\''val2'\'' --cc '\''val4'\'' --dd '\''val4'\'' --ee '\''val5'\'' --ff '\''val6'\'' --gg '\''val7'\'' --'
Run Code Online (Sandbox Code Playgroud)

如果我删除最后一个选项:hh,它工作正常。

if ! options=$(getopt -n myscript -l a:,b:,cc:,dd:,ee:,ff:,gg: -- "$@"); then exit 1; fi
Run Code Online (Sandbox Code Playgroud)

bash shell getopt

3
推荐指数
1
解决办法
6145
查看次数

标签 统计

bash ×1

getopt ×1

shell ×1