On Sat, Mar 10, 2001 at 12:35:04PM +0000 or so it is rumoured hereabouts,
Paul J Collins thought:
> >>>>> "CD" == Conor Daly <conor.daly at oceanfree.net> writes:
>> CD> Using getopts to parse a commend line to a bash script I can
> CD> read one-letter options ( -o) but not long option names (
> CD> --option-name). Can this be done? Perhaps a case for an
> CD> option of "-" and then a case construct on $OPTARG to catch
> CD> the actual option but this requires a manual reading of the
> CD> next commandline arg and and increment of OTPIND to avoid
> CD> breaking the (continuing) getopts loop. There's gotta be a
> CD> better way eh?
>> The way GNU configure scripts do it looks fairly straightforward,
> especially if you don't bother to allow abbreviation of the arguments.
Had a look at a .configure and saw a nice
-*=*)
case which was all very nice until I looked further down and saw a
gazillion lines of the form
-cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
| --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
cache_file="$ac_optarg" ;;
Thinking about it, this just allows abbreviation of the argument and can
be dispensed with. The seperation of the value from the option is nicely
done with
case "$ac_option" in
-*=*) ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
where $ac_option is what comes in on the commandline though this only
works for long options of the form
--long-option=value
^
It will break for
--long-option value
^
Is whitespace usually allowed for long options anyhow?
Incidentally, what is "ac_option" It seems to hold the commandline
arguments but I can't see where it gets them somewhere in 8k lines of
code.
--
Conor Daly <conor.daly at oceanfree.net>
Domestic Sysadmin :-)
---------------------
Faenor.cod.ie
8:19pm up 14 days, 6:54, 0 users, load average: 0.00, 0.00, 0.00
Hobbiton.cod.ie
7:24pm up 14 days, 5:34, 1 user, load average: 0.00, 0.00, 0.00
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!