I have the below if statement. It gives me syntax error when I have both the csv file and the zip file in the folder. But it works when I have the csv file alone or the zip file alone or no files exist.
I’m not sure what causes the syntax error in the command below:
if [ -f ctf_error_report_??_????????????.csv -o -f ctf_error_report_??_????????????.???.zip ];
then
echo "Successful"
else
echo "Problem"
fi
exit 0
Any insight regarding this?
This is a dangerous way to check for files. If you happen to have more than one match in that directory then it won’t work because each file will become a separate parameter, which won’t match the syntax of the text. A better (although not foolproof) way to do it is like this: