[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cp treats filename starting with a dash as a parameter

From: Bob Proulx
Subject: Re: cp treats filename starting with a dash as a parameter
Date: Thu, 29 Aug 2002 10:39:31 -0600
User-agent: Mutt/1.4i

Adam Nielsen <address@hidden> [2002-08-28 18:55:39 +1000]:
> When I type a command such as this:
> $ cp * /some/folder
> And there is a file called "-CAT_NO3.022" in the current directory, I get 
> this response:
> cp: invalid option -- C
> Try `cp --help' for more information.
> It looks as if the "-C" at the start of the filename is being treated as a 
> parameter to cp.  I'm using fileutils 4.1 (Linux x86 2.4.18, ext3.)  Please 
> let me know if I've found a real live bug!

Sorry, no bug here.  The shell expands '*' glob characters and invokes
the command.  The command does not see the '*' but only sees
characters on the command line.  In the strictest sense your command
'cp * /some/folder' is unreliable because it depends upon the contents
of the directory.

Since the file name begins with a '-' it looks like an option to the
command.  You need to force it to not look like an option.  Put a ./
in the front of it.  Or give it the full file name path.  Or tell the
command you are through with options by using the double dash to end
all option processing.  This is common to most traditional UNIX

  cp ./* /some/folder
  cp -- * /some/folder

And the same for other utilities too.

  mv ./-stuff differentstuff
  mv -- -stuff differentstuff

The FAQ contains more information.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]