From: Brian Foster (blf at domain utvinternet.ie)
Date: Fri 21 Jun 2002 - 01:36:16 IST
I'm writing a wrapper shell script around less(1) for various
bizarre reasons that are not particularly relevant, and in the
process of doing so, also experimenting with GNU getopt(1),
rather than the Bourne-ish shells's builtin getopts(1).
the issue is there's a handful of -short/--long-options my script
handles, and everything else (options and filenames) is to be
passed on to `less'. this is relatively easy to do with a
hand-coded argument parser; slightly harder but AFAIK possible
with the extended `getopts' builtinto the Korn and bash shells
(but not the basic one in the System V Bourne shell); but does
not seem possible at all with GNU `getopt'!?
roughly speaking, GNU `getopt' takes arguments, e.g.:
-a -bc argC --foo file1 --spam=xyzzy file2
...and rewrites them in a quoted canonical form:
'-a' '-b' '-c' 'argC' '--foo' '--spam' 'xyzzy' '--' 'file1' 'file2'
...according to a specification. in the example above, that
specification must have said `-a' and `-b' are valueless short
options, `-c' is a short option which takes a value, `--foo'
is a valueless long option, and `--spam' is a long option which
takes a value:
unset GETOPT_COMPATIBLE POSIXLY_CORRECT
getopt -o abc: -l foo,spam: ...
so far so good. however, if an unknown option-looking-arg (one
which starts with a `-') is encountered, I cannot find any way
of telling GNU `getopt' to treat it as just another string to
position after the `--' in the rewritten form. e.g., if `--foo'
in the above was *not* part of the spec, then I want `getopt' to
rewrite the arguments to be:
'-a' '-b' '-c' 'argC' '--spam' 'xyzzy' '--' '--foo' 'file1' 'file2'
...but there does not appear to be any way of doing this!??
am I overlooking something? (some trick or idiom?)
or is it that inflexible? (I'm using «getopt (enhanced) 1.1.2».)
ideas? comments? suggestions??
-- Innovative, very experienced, Unix and | Brian Foster Dublin, Ireland Chorus (embedded RTOS) kernel internals | e-mail: blf at domain utvinternet.ie expert looking for a new position ... | mobile: (+353 or 0)86 854 9268 For a résumé, contact me, or see my website http://www.blf.utvinternet.ie Stop E$$o (ExxonMobile): «Whatever you do, don't buy Esso --- they don't give a damn about global warming.» http://www.stopesso.com Supported by Greenpeace, Friends of the Earth, and numerous others...
This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:17:23 GMT