bash-handbook icon indicating copy to clipboard operation
bash-handbook copied to clipboard

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

Open samumbach opened this issue 9 years ago • 0 comments

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" ]]

samumbach avatar Jan 31 '16 20:01 samumbach