4 ms·
The test command has certain rules depending on the number of arguments. The most pertinent rule is: For one argument, the expression is true if, and only if,
by stantona 11y ago
The test command has certain rules depending on the number of arguments.
The most pertinent rule is:
For one argument, the expression is true if, and only if, the argument is not null.
In this case
[ -n $var ]
is the same as
test -n $var
$var is not quoted, so when this command is run, word splitting occurs and therefore $var is null. Which there falls into the one argument rule above.
Therefore, always quote your variables.