[wplug] Dumb question on rm or mv

Bob Schmertz rschmertz at speakeasy.net
Fri Aug 1 19:39:18 EDT 2003


Kuzman Ganchev incurred the wrath of Bob on Aug 1, by saying

>On Fri, Aug 01, 2003 at 06:59:37PM -0400, Russ Schneider wrote:
>> I mistakenly generated a file name -08-01-2002.sql
>> Now, when I try and rm or mv it, I get an error because the system 
>> thinks it's an option because of the -.
>> 
>> How to I rm this file?
>
>rm -- -08-01-2002.sql
>
>the -- means none of the rest of this line is options. mv, cp also
>understand this. 

Good point, I meant to mention this, because Russ seemed to reflect a
misunderstanding in the statement "the system thinks it's an option
because of the -."  Leading hyphens are just another character as far as
the "system" is concerned, whether you mean the Linux kernel or the
shell.  The hyphen is merely a Unix convention that is followed by most
standard Unix utils.  Each utility (mv, rm, etc.) must on its own decide
whether an argument beginning with a dash, or a double-dash, or a caret
means something special.  Many, of course, use the getopt() C library
function to handle arguments, and those that do behave in ways similar
to each other.

This is why someone else's suggestion, putting quotes around the file
name, WON'T work; the quotes serve only to group words into a single
argument and, in the case of single quotes, prevent the shell from
performing other expansions like variable (a.k.a. "parameter")  
expansion, subshell execution, etc.  But the shell passes that hyphen
right along to the rm command, whereupon rm says, "OK, I see all the
options you want, but where's the name of the file to be removed (and
who ever heard of a -. option??)?"

-- 
Cheers,
Bob Schmertz






More information about the wplug mailing list