conditional-operator
Bash || — conditional OR
At least one condition must be true. When the left condition is true, Bash skips the right condition. Do not confuse this operator with || connecting two complete commands or with an arithmetic logical expression. Run the example independently in a fresh private directory. Expected output (one item per line): allowed=0; denied=1.
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
mode=dev[[ $mode == dev || $mode == test ]]; printf 'allowed=%s\n' "$?"mode=prod[[ $mode == dev || $mode == test ]]; printf 'denied=%s\n' "$?"