I am trying to run find command in a script to list out certain files based on a patter. However, when there is no file in the output, the script should exit.
Tried a couple of operators (-n, -z) etc but the script does not work.
I am confused whether a null string is returned or something else since it seems null string operators are not working.
a=$(find . -name '*.lis')
if [ ! -z "$a" ] ; then
for fname in $a # have some files
do
echo $fname
done
else
echo 'no files found'
fi
Start with that. Without seeing your code, make sure any [ or ] character (if condition ) is surrounded by spaces. This will work in /bin/sh the POSIX shell. More Questions? please post your code - this was a guess.