In the last episode (Sep 25), Matthew Emmerton said: > Maybe I'm missing something huge, but getopt(1,3) aren't working the > way I think they should. > > gabby# getopt k:s: -k -s > -k -s -- > gabby# > > Wha? Neither of these options specified arguments! I guess you > could consider that -k's argument was '-s', but I was pretty sure > that an option's argument couldn't start with a dash character (to > avoid the ambiguity that I'm hitting right now.)
But then how could you specify a filename argument that starts with a dash? If you accept that arguments can start with dashes there is no ambiguity. > I'm pretty sure I'm the one that's confused (not getopt), since I get > the same behaviour on -STABLE and -CURRENT. Can someone tell me how > to accomplish what I want to do? Basically, I want this: > > gabby# getopt k:s: -k arg1 -s > getopt: option requires an argument -- k > -k arg1 -- You mean "-- s" here I suppose, since -k does have an argument. getopt does this already. > gabby# getopt k:s: -k -s arg2 > getopt: option requires an argument -- k > -s arg2 -- > gabby# You'll just have to catch that in your switch-processing code, and print an error if you get an argument that starts with a dash. case $i in -s ) case $2 in -* ) echo "getopt: option requires an argument -- $i" ; exit 1 ;; esac flag_s=$2 shift; shift ;; ... esac -- Dan Nelson [EMAIL PROTECTED] To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message