Yes, in Bash, you can check whether the -e option (which causes the script to exit immediately if any command exits with a non-zero status) is set by examining the current shell options. Here are a few ways to do it:
set +o or set -oYou can check the current state of the -e option (also known as errexit) using the following command:
bashset +o | grep errexit
errexit is off, it will appear as errexit off.errexit is on, it will appear as errexit on.Alternatively, you can use:
bashset -o | grep errexit
$-The special variable $- contains the current set of options for the shell. You can check if e is present in this string:
bashecho $- | grep -q 'e' && echo "set -e is ON" || echo "set -e is OFF"
set -e is enabled, the output will include e in the string (e.g., himBHe).set -e is disabled, the output will not include e.shopt (for Bash-specific options)While shopt is typically used for Bash-specific options, set -e is a standard shell option, so the above methods are more direct.
Vibe can make mistakes. Check answers. Learn more