I want to avoid my script posting an error if I try to cp a file that does not exist.  However, I would like error messages to print out for any other error, such as insufficient permissions.  This means I can't send the messages to dev/null.  what other solutions are there to do this in a script?One option is an if statement to check if the file exists before copying, but it seems rather cluttered approach.  I think I can get what I want by adding an * in the file's name, though it seems an odd way of doing things.  is there some command line argument or other way to get what I want?
do not show error if file doesn't exist on copy, without sending to dev null
linux;bash;cp
Checking for existence will reduce the problem, but in the most general case it's a race condition.  The file could still be removed between the check and the copy attempt.Perhaps just capture all errors and drop any for file doesn't exist.Normal copy:$ cp noexist bar /tmpcp: cannot stat `noexist': No such file or directorycp: cannot open `bar' for reading: Permission deniedModified$ cp noexist bar /tmp 2>&1 | grep -v No such file or directory >&2cp: cannot open `bar' for reading: Permission denied