Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forcing 'cp' to return 0 even if file not found?

Status
Not open for further replies.

cpjust

Programmer
Sep 23, 2003
2,132
US
Is there a way to force the 'cp' command to return 0, even if the file you're trying to copy doesn't exist?
I want to do:
Code:
cp *.deb package/output
but if there are no .deb files I don't want it to return non-zero (and thereby causing my script to fail).
 
You could add a dummy file to the command, then delete the copy of that file. For example:
[tt]
cp /dev/null *.deb package/output
rm package/output/null
[/tt]
 
What does it return when you add a slash to the destination? Or do you really want every *.deb file copied to the file package/output?

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
DonQuixote:
If the directory package/output exists, the file(s) will be copied into that directory. If the directory package/output does not exist, then an error will be returned if more than one file is being copied. At least that's how I understand GNU cp operates.
 
Thanks, I actually found a work around...
Code:
(cp *.deb package/output; exit 0)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top