command line options

Arthur David Olson ado at elsie.UUCP
Sat Apr 9 10:04:12 AEST 1988


> > is the scheme idiot-proof enough to work when executed in directories with
> > files named, for example, "-l"?
> 
> If you have reason to believe that your command may have to handle
> non-option arguments with names starting with -, then follow the
> options with the -- option, which causes getopt() to stop interpreting
> arguments as options.

I clearly wasn't clear enough here.  Let's say I have a command "-w" in my
"bin" directory that I use as a shorthand for "chmod -w", and a command "-x"
that I use as a shorthand for "chmod -x".  (And yes, this is a real-life
example).  Now watch what happens with two different uses of "od -?":
one in my home directory, and one in my bin directory:

	Script started on Fri Apr  8 19:59:31 1988
	$ od -?
	od: bad flag -?
	usage: od [-abcdfhilopswvx] [file] [[+]offset[.][b] [label]]
	$ cd bin
	./bin
	$ ls
	-w		ls		patch		tclots		uusnap
	-x		mail		ream		tint		vhf
	fit		make		rumors		tip		vnews
	gel3d		mo		shar		ttyuse		who
	headlines	morebug		stats		uchist		zap
	io		narrow		sysline		unlj		zget
	j		nm		tc		uu
	linch		pairsizes	tclint		uulast
	$ od -?
	0000000  020443 027440 064542 027556 064163 005012 060543 062563 022040 020060 067151 004412 074055 026574 076167 074053
	0000040  025574 024567 061411 066557 060555 062156 022075 020060 035473 004412 027452 074053 004451 061411 066557 060555
	0000100  062156 025475 020170 035473 004412 027452 074055 004451 061411 066557 060555 062156 060475 074055 035440 005073
	0000140  025011 025457 024567 004411 067543 066555 067141 036544 073453 035440 005073 025011 026457 024567 004411 067543
	0000200  066555 067141 036544 026541 020167 035473 004412 024452 004411 067543 066555 067141 036544 061140 071541 067145
	0000240  066541 020145 030044 020140 035473 062412 060563 005143 061412 071541 020145 021444 030444 064440 005156 030011
	0000300  030574 024475 062411 064143 020157 022042 067543 066555 067141 035144 072440 060563 062547 064440 020163 061444
	0000340  066557 060555 062156 063040 066151 027145 027056 020042 037061 031046 004412 062411 064570 020164 020061 035473
	0000400  062412 060563 005143 062412 062570 020143 064143 067555 020144 061444 066557 060555 062156 021040 040044 005042
	0000440
	$ exit

	script done on Fri Apr  8 19:59:49 1988

The first time around I get the right result--a usage message.  The second
time, though, the contents of "-x" is dumped in wide format.

Moral of the story:  using "-?" to try to get messages sometimes won't work.
That's why we use "=" here at elsie.
-- 
	ado at ncifcrf.gov			ADO is a trademark of Ampex.



More information about the Comp.lang.c mailing list