command line options

Richard A. O'Keefe ok at quintus.UUCP
Tue Apr 12 15:54:50 AEST 1988


In article <21426 at bu-cs.BU.EDU>, bzs at bu-cs.BU.EDU (Barry Shein) writes:
> Doug Gwyn writes
> >In article <21419 at bu-cs.BU.EDU> bzs at bu-cs.BU.EDU (Barry Shein) writes:
> >>What's wrong with using "-help" as a special case?
> >I explained how you could exploit a feature that is ALREADY PRESENT
> >and you keep missing the point.  -help does not currently work.
> I don't miss the point, I don't see the difficulty in fixing something
> that's broken:
> Ok, let me put it this way, if -? happens to work, fine, I wouldn't
> suggest undoing it (I assume -* and -[ and -] etc work also) but if
> one line of code is touched to codify that idea it ought to be
> something like I suggest and shell metacharacters should be avoided in
> getting help.

Something which needs to be made clear is that programs which use getopt()
do not in fact support -\? as a way of printing the "usage" message.  The
real story is that *ANY* unrecognised flag (yes, including -*, -[, -], and
even -DEL) is reported AS AN ERROR.  For example, if I do "ls -\&" under
System V, this is what happens:
	% ls -\&
	ls: illegal option -- &
	usage: ls -RadCxmnlogrtucpFbqisfL [files]

The fact that -\& can be used this way is something of a freakish accident.
The fact that -\? can be used this way is less of an accident, but it is
still freakish:  '?' is the value that getopt() returns to its caller to
say that something went wrong (but note that this behaviour CAN be disabled
by the caller, so it is NOT guaranteed in all programs that use getopt).

There is an important difference between the present -\? hack and a
principled "-help" option: giving a program an invalid option is an error
and should be signalled to the command interpreter as an error, but asking
for help and getting it is not an error.  For example, if I had a script
which did something like
	echo "what program do you want help with"
	read program_name
	$program_name -help
I would not expect this script to drop dead if help WAS printed.  But -\?
is an error, will be reported as an error, and if you set the right flags,
will cause such a script to drop dead.

It has long been considered good APL style to include a HELP function in
every workspace.  I'm embarrassed to say that I usually don't include anything
more than a cursory Usage() in my C programs, but if there were some such
conventional way to do a better job I'd follow the convention.  (When I put
anything in at all, it's -help or -h.)



More information about the Comp.unix.wizards mailing list