date: 2013-12-25 14:26:49+00:00
Bash set builtin: pipefail
tags: bash, linux
By default, if you pipe commands, the exit status reported will be the one of the last command.
ls -l test.txt | mail -s "test" email@example.com
If test.txt doesn't exist, the exit status would still be 0 because the mail command was successful.
If you want to change that behavior, you should enable the pipefail builtin:
> false > echo $? 1 > true > echo $? 0 > false | true > echo $? 0 > set -o pipefail > false | true > echo $? 1