In addition to the problems with word splitting the other answers point out, there's another problem with [ -z ${silent_install} ]
. In one of the expected cases, where silent_install
is unset or blank, the test command expands to [ -z ]
. When the [
command gets an expression with just a single argument, it tests that argument to see if it's non-blank. In this case, "-z" is non-blank, so the test returns true. This is the expected result, but that's just a coincidence; it's actually testing something very different from what the script author assumed it was.
The more serious variant of this scripting problem is the reverse test, [ -n ${somevar} ]
(-n
means "is not blank", the opposite of -z
). Because [ -n ]
actually tests whether -n
is non-blank, it returns true, which is the opposite of what you'd expect.
The moral of the story is "double-quote your variable references!" It prevents all sorts of weird bugs and unexpected behavior.