read value from file and compare, why syntax error?

Ralf Mardorf kde.lists at yahoo.com
Mon Dec 14 01:00:55 UTC 2020


On Sun, 13 Dec 2020 19:36:01 -0500, Paul Smith wrote:
>If your if-condition is a string comparison then case can be
>substituted, but if your if-condition is anything else then case won't
>help.

My apologies, I should have mentioned this.

On Sun, 13 Dec 2020 18:08:20 -0500, Paul Smith wrote:
>I'm not sure why you got the error you did; it seems like bash should
>have been able to provide a better one.

Maybe because "else" makes no sense at all, even with the semicolon at
the correct position.

There's absolutely no need to use "else", if the if-condition is
false.

I suspect that you and I agree that

if [ "$NEXTDAY" = "$LASTDAY" ]; then
  echo "Already created jobs for this day ( $NEXTDAY )!"
  exit
else
  echo "$NEXTDAY" > "$LOGFILE"
fi

results in the same as

if [ "$NEXTDAY" = "$LASTDAY" ]; then
  echo "Already created jobs for this day ( $NEXTDAY )!"
  exit
fi
echo "$NEXTDAY" > "$LOGFILE"

does. There are tools available to check scripts against errors and to
provide alternatives, maybe one or the other tool is able to detect the
OP's chain of thought. I'm not surprised that bash doesn't provide a
good pointer, since "else" with or without the semicolon in the right
position, is absurd.




More information about the ubuntu-users mailing list