bash script: how to check stderr after command "find"
I use command "find" in my bash script: if the filename exist command find work quiet, and if the filename not exist I see the message "find: /tmp/filename: No such file or directory".
My problem is following, i want to have in my script something like this: find "/tmp/filename" -type f -delete | "if no_any_errors execute command1" , if file_not_found execute command2" Does it possible? |
The error message is due to the fact that you use the name of the file you want to look for as the search path of the find command. Usually find is in the form
Code:
find /tmp -name filename However if you do Code:
find "/tmp/filename" -type f What I am trying to tell is that the find command is not suitable for the task you want to achieve, because the exit code of find is not strictly related to the existence of the file you're searching. If you're looking for the existence of a particular file, just use test -f and act accordingly to the result. For example: Code:
if [ -f /tmp/filename ] |
All times are GMT -5. The time now is 12:48 PM. |