conditional-operator
Bash ! — negate a conditional expression
In a conditional expression, ! reverses true and false. This differs in grammatical context from ! preceding a pipeline; it is not a filename pattern or arithmetic factorial. Parentheses can group conditional expressions. Run the example independently in a fresh private directory. Expected output (one item per line): empty=0; nonempty=1.
Formal Syntax & Structure
bash syntaxbash
[[ ! expression ]]Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| expression | condition | Conditional expression to negate. |
Return Value
exit status
0 for a true condition; 1 for a false condition. Invalid expressions may fail differently.
Working Example
Example Snippetbash
value=[[ ! -n $value ]]; printf 'empty=%s\n' "$?"value=yes[[ ! -n $value ]]; printf 'nonempty=%s\n' "$?"