Consistently Inconsistent 29 % rm -file usage: rm [-rif] file ... % rm ?file usage: rm [-rif] file ... % rm ????? usage: rm [-rif] file ... % rm *file2 usage: rm [-rif] file ... % rm interprets the file’s first character (the dash) as a command-line option then it complains that the characters “l” and “e” are not valid options. Doesn’t it seem a little crazy that a filename beginning with a hypen, espe- cially when that dash is the result of a wildcard match, is treated as an option list? Unix provides two independent and incompatible hack-arounds for elimi- nating the errantly named file: % rm - -file and: % rm ./-file The man page for rm states that a lone hypen between the rm command and its first filename tells rm to treat all further hypens as filenames, and not options. For some unknown reason, the usage statements for both rm and its cousin mv fail to list this “feature.” Of course, using dashes to indicate “please ignore all following dashes” is not a universal convention, since command interpretation is done by each program for itself without the aid of a standard library. Programs like tar use a dash to mean standard input or standard output. Other programs sim- ply ignore it: % touch -file touch: bad option -i % touch - -file touch: bad option -i Amuse Your Friends! Confound Your Enemies! Frequently, Unix commands give results that seem to make sense: it’s only when you try to apply them that you realize how nonsensical they actually are:
30 Welcome, New User! next% mkdir foo next% ls -Fd foo foo/ next% rm foo/ rm: foo/ directory next% rmdir foo/ rmdir: foo/: File exists Here’s a way to amuse and delight your friends (courtesy of Leigh Klotz). First, in great secret, do the following: % mkdir foo % touch foo/foo~ Then show your victim the results of these incantations: % ls foo* foo~ % rm foo~ rm: foo~ nonexistent % rm foo* rm: foo directory % ls foo* foo~ % Last, for a really good time, try this: % cat - - - (Hint: press ctrl-D three times to get your prompt back!) Online Documentation People vote for president more often than they read printed documentation. The only documentation that counts is the stuff that’s on-line, available at the tap of a key or the click of a mouse. The state of Unix documentation, and the amount by which it misses the bar, has earned its own chapter in this book, so we’ll take this space just to point out that Unix’s man system fails most where it is needed most: by novices. Not all commands are created equal: some are programs invoked by a shell, and some are built into a shell.8 Some have their own man pages. Some don’t. Unix expects you to know which is which. For example, wc, cp, and ls are programs outside of the shell and have man pages. But fg, jobs, set,