Afficher un message
Vieux 25/08/2006, 08h24   #7
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Trying to copy all *.csv files to another directory but fails -

On 2006-08-24, Bill Marcum wrote:
> On 24 Aug 2006 10:10:52 -0700, phillip.s.powell@gmail.com
> <phillip.s.powell@gmail.com> wrote:
>>
>> Stephan 'smg' Grein wrote:
>>> -----BEGIN PGP SIGNED MESSAGE-----
>>> Hash: SHA1
>>>
>>> phillip.s.powell@gmail.com wrote:
>>> > # NOW WE COPY EVERYTHING OVER TO THE NEW FOLDERS IN $csvBackupPath
>>> > cp -pr "$clientDocPath/*.csv" "$csvBackupPath/clientCSV"
>>> > cp -pr "$projectDocPath/*.csv" "$csvBackupPath/projectCSV"
>>> >
>>> Try that:
>>> cd "$clientDocPath/" && for file in *.csv; do cp -p "$file"
>>> "$csvBackupPath/clientCSV/${file}"; done
>>> cd "$projectDocPath/" && for file in *.csv; do cp -p "$file"
>>> "$csvBackupPath/projectCSV/${file}"; done
>>>
>>> > This code I thought would simply copy everything ending in ".csv" to
>>> > another directory, but I get the following error:
>>> >
>>> > No such file or directory *.csv
>>> You got wrong with the * quantifier.
>>> >
>>> > What must I do to ensure copying files over?
>>>
>>> try above

>>
>> Could you please explain that? None of it made sense to me, what is
>> that/??
>>

> In sh and similar shells, if there is no file matching a wildcard
> expression, the wildcard expression is left as is on the command
> line. To avoid an error, you can use
>
> if [ -f "$clientDocPath/*.csv" ]; then


That doesn't work, because the wildcard will not be expanded.

> cp -pr "$clientDocPath/*.csv" "$csvBackupPath/clientCSV"
> fi
>
>



--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
 
Page generated in 0,18479 seconds with 9 queries