sstephenson/bats

Why use [ over [[ ?

Closed this issue · 2 comments

The newer [[ offers more syntactic sugar and is a Bash built-in so why using the older [ ?

[ is also a bash builtin, in addition to being an actual executable in the system. The builtin takes precedence.

Simply put, we're using [ everywhere where [[ is not needed, and [[ is only superior when it comes to pattern matching and complex boolean expressions. In every other case, [ is just fine, and the advantage of expressions written in a simpler way is that people can study them and copy into a POSIX-compatible shell and they will still work.

For reference: [What is the difference between test, [ and [ ?