If there are spaces around the operator, test
returns the correct value of the expression.
But if there are no spaces, it doesn't throw any syntax error and always return true.
$ test "A" == "A"; echo $?
0 #<-- OK, 0 stands for true
$ test "A" == "B"; echo $?
1 #<-- OK, 1 stands for false
$ test "A"=="A"; echo $?
0 #<-- OK, 0 stands for true
$ test "A"=="B"; echo $?
0 #<-- ??? should either return 1 (false), or throw a syntax error (exit code > 1)
==
operator isn't standard, so you might want to use=
instead for compatibility with all shells. – ilkkachu Oct 28 '22 at 10:48