command line options

Chip Salzenberg chip at ateng.UUCP
Mon Apr 11 23:41:41 AEST 1988


What's so hard about typing '-\?' to get help?  I do it all the time.
And it works in any shell and despite strangely named files.

BTW, the argument against '-?' that goes "but what if I have a file named
'-r'" is not very strong, since such a file kills you even if you don't
ask for help:

	% ls -F
	-r
	foo
	bar
	important/
	% rm *          [pronounced "rim splat", by the way]
	% ls
	%               [anguished scream]

Kaboom.

For those of you who want to make your programs a bit safer to use than rm,
here is an idea:  Before parsing for options, check to see if any arguments
that begin with '-' are actually the names of existing files.  If they are,
emit a suitably alarming warning message and enable the "interactive"
option so the user has a chance to back out.

And if you see an argument '--', check to see if a file by that name exists,
then stop looping since the rest of the arguments are not options.

Of course, this gets complicated by a call to isatty(), since you don't
want a cron task waiting for operator input; so perhaps this ends up being
more of a kludge than a safety belt.  But if your program is sufficiently
destructive, CYA is a worthwhile policy.

--
Chip Salzenberg                 "chip at ateng.UU.NET" or "codas!ateng!chip"
A T Engineering                 My employer's opinions are a trade secret.
       "Anything that works is better than anything that doesn't."



More information about the Comp.unix.wizards mailing list