The reason for this is that there are some commands that accept switches of the form$ rm -foo usage: rm [-rif] file ...
-switch. As an example the
following command will produce a long listing of the contents of the
directory.ls -l
There are several more commands that accept switches, rm
is among them.
When you type a line to the shell, quoting will prevent any expansion
done by the shell, but in this case -foo will be passed
to rm, which will interpret this as a switch. There is no
-o switch to rm, so rm will
print an error message
To solve this problem you have to type a name to
rm that does not start with a -,
but which still denotes the file -foo. Remembering that
. denotes the current directory gives us the following
line, which remove the file -foo from the current
directory.
rm ./-foo