sstephenson / bats

Bash Automated Testing System
MIT License
7.13k stars 517 forks source link

Why use [ over [[ ? #186

Closed edouard-lopez closed 8 years ago

edouard-lopez commented 8 years ago

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

mislav commented 8 years ago

[ 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.

edouard-lopez commented 8 years ago

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