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: