removing a file with hyphens

Paul LeoNerd Evans leonerd at leonerd.org.uk
Thu Jun 7 11:56:16 BST 2007


On Thu, 07 Jun 2007 11:32:28 +0100
Paul Orrock <paulo at digitalcraftsmen.net> wrote:

> paulo at kryten:~$ rm *riginal
> rm: unrecognised option `-----Original'
> Try `rm --help' for more information.
> paulo at kryten:~$ mv '\-\-\-\-\-Original' old
> mv: cannot stat `\\-\\-\\-\\-\\-Original': No such file or directory
> paulo at kryten:~$ mv '-----Original' old
> mv: unrecognised option `-----Original'
> Try `mv --help' for more information.
> paulo at kryten:~$ mv \-\-\-\-\-Original old
> mv: unrecognised option `-----Original'
> Try `mv --help' for more information.
> paulo at kryten:~$ mv "\-\-\-\-\-Original" old
> mv: cannot stat `\\-\\-\\-\\-\\-Original': No such file or directory
> paulo at kryten:~$ rm '\-\-\-\-\-Original'
> rm: cannot remove `\\-\\-\\-\\-\\-Original': No such file or directory

All of those result in the same arguments being passed into rm, because
the escaping is all done by bash, before it fork()+exec()s; compare

   exec( "/bin/rm", "------Original" );

What you need is to pass the "--" option, which getopt interprets as
"here's the end of the options, all the rest are file names:

  rm -- ------Original

which comes out as

  exec( "/bin/rm", "--", "------Original" );

-- 
Paul "LeoNerd" Evans

leonerd at leonerd.org.uk
ICQ# 4135350       |  Registered Linux# 179460
http://www.leonerd.org.uk/


More information about the london.pm mailing list