Although the problem was solved in a comment above, let me give you a bit more information.
For Bash, [
is a command, and there is nothing special about that command. Bash parses the following arguments as data and operators. Since these are normal arguments to a normal command, they need to be separated by spaces.
If you express a test as ["lol" = "lol"]
, Bash reads this as it would read any command, by performing word splitting and expansions. This gets rid of quotes, and what is left after that is [lol = lol]
. Of course, [lol
is not a valid command, so you get the error message you saw.
You can test this with another command. For instance, type l"s"
at the command line, and you will see Bash execute ls
.
You would not write ls/
(without the space), so for the same reason you cannot write [a=b]
either.
Please note ]
simply is a closing argument that command [
expects. It has no purpose in itself, and requiring it is simply a design choice. The test
command actually is entirely equivalent to [
, aside from not needing the closing bracket.
One last word... [
is a builtin in Bash (meaning a command that is part of Bash itself and executes without launching a separate process, not a separate program), but on many systems you will also find an executable named [
. Try which [
at the command line on your system, it will probably be there.