I've written a script to check files in different directories and want this script to show me error in case a file does not exists. But It show me Both ERROR and NO ERROR due to loop. ow to adjust so that i could get only ERROR or NO ERROR in case one or more files are missing or all are existing into their directories.
files=("/my/path/to/file1.tar.gz" "/my/path/to/file2.tar.gz")
for i in "${files[@]}"
do
ls -l $i
if [ $? -ne 0 ]; then
echo "ERROR"
else
echo "NO ERROR"
fi
done
I cannot add exit, If i'll added then rest of the script below to this will stop. ls is not important. Important is to check the existence of files. It can be whatever with any way either if [ -e "/path/to/file"] etc. However ERROR is important, because in case of error or no error, i'll send an email to myself that is why its important.
Can you please explain, why you use 'set -e'?
Its not working as i want. Its printing information line by line. But i want it to store information for all and printer error if any of one is missing or no error if all exists. How is it possible to do????