Reputation: 6391
I'm testing getopt for my bourne script and I'm finding some very interesting results.
#!/bin/sh
params=$(getopt lLo:p:t: "$*")
exit 0
If I do the following:
./myscript -z blah -o legal -p another_legal
As expected I will get:
getopt: illegal option -- z
getopt: illegal option --
getopt: illegal option -- b
getopt: illegal option -- l
getopt: illegal option -- a
getopt: illegal option -- h
But if I do this:
./myscript -o legal -p another_legal -z blah
getopt
does not catch this. Any ideas why?
Upvotes: 0
Views: 839
Reputation: 56059
"$*"
passes all arguments your function received as a single argument to getopt
. So you're essentially running getopt lLo:p:t: "-o legal -p another..."
You want "$@"
instead.
Upvotes: 3