Joined December 2020
·

kernrad

Well, you are right.
I only wanted to complete the example, nothing more, for this property is used for error exit but not directly visible. The article is correct.

It's different by use of the returncode. Without -o pipefail we will get the returncode of echo "a", which is 0. By use of -o pipefail it is the returncode of foo which is not found and therefore returns 127.

I'd like to complete -o pipefail. In your example there is a further property of this option invisible.
Let's look at:

Before

$ foo | echo "a"
$ echo $?
$ echo bar

a

bash: foo: Kommando nicht gefunden.

0

bar

After

set -o pipefail
$ foo | echo "a"
$ echo $?
$ echo bar

a

bash: foo: Kommando nicht gefunden.

127

bar

See manpage bash:
"The return status of a pipeline is the exit status of the last command, unless the pipefail option is enabled. If pipefail is enabled, the pipeline's return status is the value of the last (rightmost) command to exit with a non-zero status, or zero if all com mands exit successfully."

Achievements
1 Karma
0 Total ProTip Views