From man bash
:
-n string
True if the length of string is non‐zero.
Examples:
# expected
$ var=""; [ -n "$var" ]; echo $?
1
# unexpected?
$ var=""; [ -n $var ]; echo $?
0
Here we see that -n
with unquoted variable containing empty string returns true. Why?
Why is $var
is required to be quoted here?