Bash set builtin- pipefail

author: admin
comments: false

layout: post

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"

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 $?
> true
> echo $?
> false | true
> echo $?
> set -o pipefail
> false | true
> echo $?

Thanks for reading this post!

Did you find an issue in this article?

- click on the following Github link
- log into Github with your account
- click on the line number containing the error
- click on the "..." button
- choose "Reference in new issue"
- add a title and your comment
- click "Submit new issue"

Your feedback is much appreciated! πŸ€œπŸΌπŸ€›πŸΌ

You can also drop me a line below!