TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
-n operator is a unary string evaluation operator in Bash that tests whether a given string has a non-zero length. When executed within a test command construct, it returns an exit status of 0 (true) if the string contains one or more characters, and an exit status of 1 (false) if the string is empty (null) or an unassigned variable.
Syntax
- Operand: Accepts a single string argument.
- Return Value: Yields
0(success/true) forlength > 0. Yields1(failure/false) forlength == 0. - Inverse: The
-noperator is the exact logical inverse of the-zoperator, which tests for a zero-length string.
[ ] or the test builtin, the string operand must be enclosed in double quotes ("$VARIABLE"). If the variable is unquoted and evaluates to null, the shell performs word splitting before the test command executes. This expands the expression to [ -n ].
In this unquoted scenario, Bash’s parsing rules interpret the isolated -n as a literal non-empty string argument rather than a unary operator, erroneously returning an exit status of 0.
[[ ]] (extended test command), word splitting and pathname expansion are suppressed. Consequently, [[ -n $VAR ]] will correctly evaluate to false if the variable is empty. However, double-quoting the variable remains the standard technical convention to ensure predictable behavior across different shell environments and test constructs.
Master Bash with Deep Grasping Methodology!Learn More





