bash-handbook
bash-handbook copied to clipboard
Add note about whitespace when introducing `[ ]` and `[[ ]]`
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" ]]