read value from file and compare, why syntax error?

Paul Smith paul at mad-scientist.net
Sun Dec 13 23:08:20 UTC 2020


On Mon, 2020-12-14 at 00:00 +0100, Bo Berglund wrote:
> if [ "$NEXTDAY" == "$LASTDAY" ] then;

this is wrong: the semicolon should be before the "then" not after it:

  if [ "$NEXTDAY" = "$LASTDAY" ]; then

(I used = not == because the former is POSIX conforming).

The "condition" of an if-statement can be an arbitrarily complex
command to run, so it needs a semicolon to end it.

I'm not sure why you got the error you did; it seems like bash should
have been able to provide a better one.





More information about the ubuntu-users mailing list