I’m putting together a simple backup script that will tar contents of a folder, then move that file to a backup server. The script makes sure that the tar file exists and is not zero bytes before moving around.
The problem is that the script is dying on one of the IF lines
if [ -f /www/archives/pdf/pdf_201207021048.tar && 11294720 -gt 0 ]; then
echo "tar file exists and is greater than 0 bytes."
else
echo "tar file does not exist or is zero bytes"
fi
The error in the console is:
./backup_pdf.sh: line 49: [: missing `]'
Line 49 is the if statement above.
The script is successfully verified with
bash -n backup.sh
What’s wrong that bash is seeing a missing ‘]’, yet it passes the syntax check?
The && operator separates commands, so your
[and your]aren’t part of the same command, as is required. Either use two sets of brackets with a && between them, or use the-aoperator. Most people prefer the first option these days.