-o OPTION (conditional operator)

true if the shell option OPTION is enabled.

-o is not included in POSIX.1-2017.

-o is not to be confused with the -o OR operator as in [ a -o b ], e.g. [ -o xtrace -o -o monitor ] && echo xtrace or monitor option enabled. This OR operator is not well-defined, the better alternative in Bash is [[ a && b ]]. Some, but not all POSIX shells implement the -o OR operator.

Examples

Different ways to test if a shell option is enabled:
1
2
3
4
test -o xtrace && echo "xtrace enable"
[ -o xtrace ] && echo "xtrace enabled"
# Bash
[[ -o xtrace ]] && echo "xtrace enabled"
BashSupport Pro ist eine Bash IDE mit Unterstützung für -oprobieren Sie es aus!
© 2020–2024 Joachim Ansorg
Impressum
Datenschutz
Rechtliches