Difference of -e, -u and -o pipefail in bash exit status

Viewed 1212

Being trying to properly guard for non-zero exits on a bash script.

What is the difference between -e, -u and -o pipefail?

-o pipefail is not sufficient to exit with an error code?

1 Answers

set -e: Exit immediately if a command exits with a non-zero status.

set -u: If you try to access an undefined variable, that is an error.

set -o pipefail: If any command in a pipeline returns a non-zero exit code, the return code of the entire pipeline is the exit code of the last failed command.

Related