exit status of command "find"
Hi all,
I am beginner in Linux.I want to do the following (bash shell): if "find" command finds 'thereis' file in the current directory then "echo" Yes otherwise No. Any ideas? I tried to use exit status of "find" but it gives the same result in both cases. |
Check the man page for find. The definition of the return status is rather broad, but it basically refers to all files having been processed successfully, not whether it found what you were looking for. There are other ways in the shell of asking whether a file exists or not.
|
Yes, exit status won't do it here. A slightly messy indirect way would be to count the number of lines (matches) that find outputs:
Code:
if test `find . -name $filename | wc -l` -gt 0; then Code:
if [ -e $filename ]; then |
Thanks
|
All times are GMT -5. The time now is 06:28 AM. |