Skip to main content
1 of 2
kjo
  • 16.4k
  • 25
  • 76
  • 124

[ vs [[ : which one to use in bash scripts?

The zsh man page, in its section on test (aka [), explicitly advises against using it at all, and urges readers to use [[ whenever possible.

I think I've come across similar advice for bash, but as I scan over the bash man page I can't find any "official" recommendation there on which form ([ or [[) to use. (Maybe I missed it?)

Is there any reason, other than backward compatibility with "older shells", for using [ in a bash script? Or to put it differently, does bash keep [ along with [[ for reasons other than backward compatibility?

kjo
  • 16.4k
  • 25
  • 76
  • 124