In the following code
a=
[ -n $a ]
echo $?
[ -z $a ]
echo $?
Why the op is
In the following code
a=
[ -n $a ]
echo $?
[ -z $a ]
echo $?
Why the op is
Quote the variable and you'll get the correct result.
The -n test requires that the string be quoted within the test brackets. Other test operators, or using no operator (implied -n), will generally work as you would expect without quoted strings. But, to be safe, it is generally recommended that you always quote your strings when testing.
a=
[ -n $a ]
echo $?
[ $a ]
echo $?
Output:
0
1