Other than the portability benefits of [
and the newer features and safety/correctness properties of [[
that have already been discussed there is one downside to using [[
that is worth being aware of (to my mind).
Specifically, what happens when you use it to validate/etc. numeric values.
I asked a question here about it.
I also discussed it in the comments on this answer.
Specifically, this
foo=bar
[ 5 -eq "$foo" ]
will output an error and [
will return 2
whereas this (with or without quotes around the variable)
foo=bar
[[ 5 -eq "$foo" ]]
will silently return 1
and this
bar=5
foo=bar
[[ 5 -eq "$foo" ]]
will return 0
.
That is [[
evaluates bare-variables recursively. It also, as indicated in ruakh's comment on chepner's answer will expand expressions in variables.
So
foo="10 / 2"
[[ 5 -eq "$foo" ]]
will also return true.
Now, this may be exactly what you want but means you have to work harder to validate input/etc. then you would with [
.