[[
has fewer surprises and is generally safer to use. But it is not portable - Posix doesn't specify what it does and only some shells support it (beside bash, i heard ksh supports it too). For example, you can do
[[ -e $b ]]
to test whether a file exists. But with [
, you have to quote $b
, because it splits the argument and expands things like "a*"
(where [[
takes it literally). That has also to do with how [
can be an external program and receives its argument just normally like every other program (although it can also be a builtin, but then it still has not this special handling).
[[
also has some other nice features, like regular expression matching with =~
along with operators like they are known in C-like languages. Here is a good page about it: What is the difference between test, [
and [[
? and Bash Tests
[[
with it the code is good and clear, but remember that day when you'll port your scriptworks on the system with default shell which is notbash
orksh
, etc.[
is uglier, cumbersome, but works asAK-47
in any situation. – rook Aug 15 '13 at 20:20