Re:Use the Unofficial Bash Strict Mode (Unless You Love Debu...
by stantona on Sunday March 20, 2016 @11:28AM
(#11323277)
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.
In this case
is the same as $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.