In bash, are [[ $variable ]]
and [[ -n $variable ]]
completely equivalent? It appears to be the case judging by the output below, but I see both forms of usage prevalent in shell scripts.
$ z="abra"
$ [[ $z ]]
$ echo $?
0
$ [[ -n $z ]]
$ echo $?
0
$ z=""
$ [[ $z ]]
$ echo $?
1
$ [[ -n $z ]]
$ echo $?
1
$ unset z
$ [[ $z ]]
$ echo $?
1
$ [[ -n $z ]]
$ echo $?
1
[[ -n $(echo -ne "\0") ]]; echo $?
and[ -n $(echo -ne "\0") ]; echo $?
differ – dchirikov Jan 30 '13 at 19:31[ -n ]
, the same[ -n -n ]
. In shells other than zsh, command (even builtin) arguments or shell variables can't contain NUL characters. – Stéphane Chazelas Jan 30 '13 at 20:29