denysdovhan / bash-handbook

:book: For those who wanna learn Bash
https://git.io/bash-handbook
5.69k stars 756 forks source link

Add note about whitespace when introducing `[ ]` and `[[ ]]` #40

Open sumbach opened 8 years ago

sumbach commented 8 years ago

I think it would be valuable to explicitly talk about whitespace requirements in [ ] and [[ ]] conditionals--this tripped me up when learning Bash and I know it's a pain point for a lot of developers.

The way I like to think about it is that [ and [[ are commands/builtins (like echo, etc), as opposed to being part of Bash syntax. For this reason, the command name and each of its arguments must be separated by whitespace:

[[ -n "$1" ]]

# not
[[-n"$1"]]
[[-n "$1"]]
[[ -n"$1" ]]