Automation, Orchestration, and Scripting
A script contains the line [ -n $CONFIG ] && echo "Config set". CONFIG is empty, yet the message still prints. What is the cause?
Show the answer
Correct answerD. The unquoted variable vanishes, leaving [ -n ], which is a single non-empty string.
Without quotes, an empty variable expands to nothing, so the test sees only the string -n and a lone non-empty string is true. Quoting as "$CONFIG" keeps the empty argument. The -n operator tests for non-zero string length, not zero length.