Why should there be spaces around ‘[‘ and ‘]’ in Bash?

Once you grasp that [ is a command, a whole lot becomes clearer!

[ is another way to spell “test“.

help [

However while they do exactly the same, test turns out to have a more detailed help page. Check

help test

…for more information.


Furthermore note that I’m using, by intention, help test and not man test. That’s because test and [ are shell builtin commands nowadays. Their feature set might differ from /bin/test and /bin/[ from coreutils which are the commands described in the man pages.

Leave a Comment