LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] unknown -options vs. GNU getopt(1)?

[ILUG] unknown -options vs. GNU getopt(1)?

Brian Foster blf at utvinternet.ie
Fri Jun 21 01:36:16 IST 2002


 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??

cheers!
	-blf-
--
 Innovative, very experienced, Unix and      | Brian Foster    Dublin, Ireland
 Chorus (embedded RTOS) kernel internals     | e-mail: blf at 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...




More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


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!
RSS Version
Powered by Dell