conditional-operator

Bash -o — option test and legacy OR

The unary -o form tests a set -o option, such as pipefail; it does not query every shopt option. The binary -o form in test/[ is legacy logical OR, affected by argument-count parsing. Prefer separate tests joined by || or [[ expression1 || expression2 ]]. These forms are not interchangeable. Run the example independently in a fresh private directory. Expected output (one item per line): disabled=1; enabled=0; legacy-or=0.

Formal Syntax & Structure

bash syntaxbash
[[ -o option ]]; [ expression1 -o expression2 ]

Parameters & Attributes

NameTypeDescription
optionoption nameName used with set -o; unary form. Required only for its respective syntax form.
expression1conditionFirst expression, legacy binary form. Required only for its respective syntax form.
expression2conditionSecond expression, legacy binary form. Required only for its respective syntax form.

Return Value

exit status

0 for a true condition; 1 for a false condition. Invalid expressions may fail differently.

Working Example

Example Snippetbash
set +o pipefail[[ -o pipefail ]]; printf 'disabled=%s\n' "$?"set -o pipefail[[ -o pipefail ]]; printf 'enabled=%s\n' "$?"[ -n '' -o -n yes ]; printf 'legacy-or=%s\n' "$?"
Bash Reference