Why do some people put a semicolon after an if condition in shell scripts? [duplicate]

if [ $a == $b ]; then
  echo "a == b"
fi

You can use a semicolon, or you can write then on a separate line. Either one is allowed.

if [ $a == $b ]
then
  echo "a == b"
fi

Having neither a ; nor a newline is a syntax error.

$ if [ $a == $b ] then
>   echo "a == b"
> fi
bash: syntax error near unexpected token `fi'

As for [ vs [[, see:

  • What’s the difference between [ and [[ in Bash?

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)