conditional-operator
Bash && — conditional AND
Both conditions must be true. The right operand is not evaluated if the left is false. This is conditional grammar inside [[ ]], distinct from && between complete commands. Run the example independently in a fresh private directory. Expected output (one item per line): empty=1; match=0.
Formal Syntax & Structure
bash syntaxbash
[[ expression1 && expression2 ]]Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| expression1 | condition | Left condition. |
| expression2 | condition | Right condition, evaluated only if needed. |
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 && $value == yes ]]; printf 'empty=%s\n' "$?"value=yes[[ -n $value && $value == yes ]]; printf 'match=%s\n' "$?"