bug-coreutils
[Top][All Lists]
Advanced

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

Re: cp should look for destination file operand BEFORE wildcardexpansion


From: Brian Dessent
Subject: Re: cp should look for destination file operand BEFORE wildcardexpansion
Date: Tue, 20 Feb 2007 05:18:05 -0800

Anshul Nigham wrote:

> 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.

You have a misconception as to how globbing works.  It is not done by
'cp' at all, it is entirely the domain of the shell.  By the time 'cp'
looks at its arguments, they are already expanded and 'cp' has no way to
differentiate whether the user specified "*.txt" or "a.txt b.txt".  You
can trivially verify this yourself with a 5 line C program that just
prints the contents of 'argv[]'.

This is by design.  The original intent of unix was along the lines of
"a lot of small programs, each that do one thing really well."  In that
vein, the shell does all globbing (and variable expansion/substitution,
quoting, etc.) for all program invocations, rather than having to add
glob expansion code to every little individual program that might ever
need to process more than one file.

Brian




reply via email to

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