bug-coreutils
[Top][All Lists]
Advanced

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

cp should look for destination file operand BEFORE wildcard expansion


From: Anshul Nigham
Subject: cp should look for destination file operand BEFORE wildcard expansion
Date: Mon, 19 Feb 2007 20:45:53 +0800

Hi

Using wildcard expansion, it is possible to unintentionally overwrite
files. E.g. consider a directory with two text files, a.txt and b.txt.

$ ls
a.txt  b.txt
$ cat a.txt
I am A!!
$ cat b.txt
I am B!!
$ cp a.txt
cp: missing destination file operand after `a.txt'
Try `cp --help' for more information.
(--- this is correct behavior ---)
$ cp *.txt
(--- Forgot to give the destination directory ---)
(--- command executes, equivalent to "cp a.txt b.txt" ---)
$ cat b.txt
I am A!!
$

I don't think this could be intended or expected behavior in any
scenario. I suggest that the cp behavior be modified to look for a
destination file operand before expanding wildcards, in which case a
command like "cp [options] wildcard-expr" would still exit with an
error of missing destination file operand, even if the wildcard-expr
expands to two or more files.

The above behavior exists as of coreutils v 6.7.

--
Regards,
Anshul




reply via email to

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