read value from file and compare, why syntax error?

Bo Berglund bo.berglund at gmail.com
Sun Dec 13 23:00:39 UTC 2020


I am baffled by this error being displayed when I run this script
command which is meant to allow only one execution per day...

I have this on top of a larger script that works flawlessly without my
extra lines to stop dual execution for a day.
The section from LOGFILE= to fi are added into the old script in order
to make it exit with an error message if it already ran that day:

#!/bin/bash
NEXTDAY=`date --date="tomorrow" +%Y-%m-%d`
LOGFILE="makeatjobs.log"
read LASTDAY < $LOGFILE
if [ "$NEXTDAY" == "$LASTDAY" ] then;
  echo "Already created jobs for this day ( $NEXTDAY )!"
  exit
else
  echo "$NEXTDAY" > "$LOGFILE"
fi
....

I get the following error on the else line:

./makeatjobs: line 8: syntax error near unexpected token `else'
./makeatjobs: line 8: `else'

Why is there a syntax error on the keyword else?????
Are if-then-else constrructs not allowed in bash? I'm sure they are...


-- 
Bo Berglund
Developer in Sweden





More information about the ubuntu-users mailing list