4

In bash: I input the command:

getopt -l name,data -- --namd

and the output is

-- name,pp -- --namd

input :

getopt -l name,data -- --name

the output alse

-- name,pp -- --name

why it dosen't tell me the err when i input getopt -l name,data -- --namd?

3
  • You may also want to look at the getopts builtin command, which is generally easier to work with. At least, I think so.
    – larsks
    Aug 2, 2012 at 12:53
  • Thanks @H2CO3, I'm a new hand here~~~~~ Aug 2, 2012 at 14:09
  • @larsks, but I want to deal the long parameter. such as: cmd --path /user --name qiushuitian -d -p 100 Aug 2, 2012 at 14:11

1 Answer 1

10

The problem is that on the mac, getopt is the BSD based getopt, rather than the gnu-based getopt.

It doesn't understand long options. It's not that it 'doesn't work well', it's that it's not designed to do what you asked.

3
  • Thanks. But if I want to deal with the long options, how can I do? Must I analyze the parameter myself? Aug 3, 2012 at 3:27
  • 2
    You can install gnu getopt from macports - stackoverflow.com/questions/402377/… Aug 3, 2012 at 7:33
  • There is a homebrew formula also: brew install gnu-getopt works too.
    – nonbeing
    Sep 15 at 6:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.