Issue
I am trying to find the number of files in a directory. I am using the ls command. Based on the Number of Files, I need to display the count and a message. Script doesn't provide the desired output. Any assistance will be appreciated.
#!/bin/sh
FILECOUNT = $(ls /opt/report/ | grep *.ZIP_30 | wc -l);
if [ $FILECOUNT -gt "0" ]; then
echo "Statistic.filecount: $FILECOUNT";
echo "Message.filecount: Normal";
else
echo "Statistic.filecount: $FILECOUNT";
echo "Message.filecount: Warning";
fi;
exit 0;
Solution
You have a syntax error.
No spaces allowed around =
in shell, so:
filecount=$(grep -c ZIP_30 /opt/report/*)
Answered By - Gilles Quenot Answer Checked By - Robin (WPSolving Admin)