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