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.

Example:

ls -l test.txt | mail -s "test" example@example.org

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



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!