2012-08-02 134 views
2

在bash:I输入的命令:为什么getopt在我的mac os中无法正常工作?

getopt -l name,data -- --namd 

并且输出是

-- name,pp -- --namd 

输入:

getopt -l name,data -- --name 

输出ALSE

-- name,pp -- --name 

为什么它多申当我输入getopt -l name,data -- --namd时,不会告诉我错误吗?

+1

啊我的大脑伤害阅读未格式化的代码... – 2012-08-02 12:45:16

+0

你可能也想看看'getopts'内置命令,这通常更容易处理。至少,我是这么认为的。 – larsks 2012-08-02 12:53:06

+0

谢谢@ H2CO3,我是这里的新手~~~~~ – qiushuitian 2012-08-02 14:09:01

回答

4

问题是,在mac上,getopt是基于BSD的getopt,而不是基于gnu的getopt。

它不理解长选项。这并不是说它“效果不好”,而是因为它不是按照你的要求设计的。

+0

谢谢。但是如果我想处理多头选项,我该怎么办?我必须自己分析参数吗? – qiushuitian 2012-08-03 03:27:55

+0

你可以从macports安装gnu getopt - http://stackoverflow.com/questions/402377/using-getopts-in-bash-shell-script-to-get-long-and-short-command-line-options – Petesh 2012-08-03 07:33:28

+0

谢谢你非常感谢! – qiushuitian 2012-08-08 03:45:06

相关问题