home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / unix / shell / 4576 < prev    next >
Encoding:
Internet Message Format  |  1992-11-07  |  2.6 KB

  1. Xref: sparky comp.unix.shell:4576 comp.unix.programmer:5187 comp.unix.wizards:4554
  2. Path: sparky!uunet!gatech!darwin.sura.net!paladin.american.edu!news.univie.ac.at!hp4at!mcsun!Germany.EU.net!pki-nbg!hitkw14!smr
  3. From: smr@pki-nbg.philips.de (Stephen Riehm)
  4. Newsgroups: comp.unix.shell,comp.unix.programmer,comp.unix.wizards
  5. Subject: Re: optarg(1) and quoted args, help wanted.
  6. Message-ID: <smr.721062269@hitkw14>
  7. Date: 6 Nov 92 15:04:29 GMT
  8. References: <smr.719847792@hitkw14>
  9. Sender: news@pki-nbg.philips.de
  10. Reply-To: smr@pki-nbg.philips.de
  11. Lines: 45
  12.  
  13. > I am trying to use getopt(1) in some /bin/sh scripts to parse the
  14. > command line options, it works fine, except I want to get around
  15. > something that we are warned against in the manpage, namely embedded
  16. > blanks in args.
  17.  
  18. > for example:
  19. > command -abc 'comment which might be long' -de file ...
  20.  
  21. In response to the huge number of replies that I have received on this
  22. topic, here is a summary:
  23.  
  24. 1. use getopts(1) if it is available.
  25. 2. there are various hacks to get the shell to interpret the output
  26.     from getopt(1), none are especially neat however, and with most you
  27.     would be just as well off if you simply threw out getopt all
  28.     together.
  29. 3. Write your own... which is exactly what I did. While I was at it I
  30.     added some extra functionality, while maintaining backward
  31.     compatibility. An offshoot of this was that I ended up with code
  32.     for my own version of getopt(3), with the extra functionality.
  33.     Basically the extra functionality is that you can specify options
  34.     which may be prefixed by a + aswell as a -, (normally +<opt> gives
  35.     you an error), and the addition of a -q and -c option to
  36.     getopt(1). -q puts quotes around args with white space, and -c can
  37.     be used to specify the name of the command to print in the event
  38.     of errors, so that instead of running a shell and getting:
  39.     getopt: Illegal option -- q
  40.     you can now get
  41.     my_cmd: Illegal option -- q
  42.     OK, they're minor changes, but they help to make the world a nicer
  43.     place.
  44.  
  45. If anyone is interested in a copy of my re-invented wheel, drop me a
  46. line and I'll send you a shar file (16kb).
  47. (PS: I haven't got around to make a manpage for it yet, but there's
  48. lotsa of comments to keep you busy)
  49.  
  50. thanks to all those who replied!
  51.  
  52. -----------------------------------------------------------------
  53. Stephen Riehm        Configuration Management       _-_|\ 
  54. smr@pki-nbg.philips.de    Philips Kommunikations Industrie  /     \
  55. Work: +49 911 526 2975    N|rnberg, Germany          \_.-.*/
  56. Fax:  +49 911 526 3678    "I was there, now I am here!"           v 
  57. "My company speaks another language, I CAN'T speak on its' behalf"
  58.