No, that is just wrong. In double-brackets, bash will handle expansion and testing of unset variables and variables with spaces just fine, because word splitting and pathname expansion are not performed in double braces -- they are shell syntax, as opposed to single brackets, which are commands. Your syntax error happened because you don't have a fi matching that if.
As a counterexample:
(echo $BASH_VERSION;
foo=foo; [[ $foo = foo ]] && echo $foo;
foo="1 2 3"; [[ $foo = "1 2 3" ]] && echo $foo;
foo=''; echo ${foo?"No foo for you"};
unset foo; echo ${foo?"No foo for you"})
4.2.10(1)-release
foo
1 2 3
bash: foo: No foo for you
That last one is one of the few ways you can tell whether a variable is unset or merely set to an empty string.
Comments
No, that is just wrong. In double-brackets, bash will handle expansion and testing of unset variables and variables with spaces just fine, because word splitting and pathname expansion are not performed in double braces -- they are shell syntax, as opposed to single brackets, which are commands. Your syntax error happened because you don't have a fi matching that if.
As a counterexample:
That last one is one of the few ways you can tell whether a variable is unset or merely set to an empty string.lrn2bash.