blog.g3rt.nl
  • Home
  • About
  • Categories
  • Tags
  • Archives

How to retain exit status codes through pipes in Bash scripts

Suppose you have a line

mysqldump | gzip

in your script. Then the exit status code will be of gzip, rather than mysqldump, while the most likely process to fail here is mysqldump.

To fix this, add this at the top of your bash scripts:

set -o pipefail

Share on: Twitter ❄ Hacker News ❄ Facebook ❄ LinkedIn ❄ Reddit ❄ Email


Published

10 Aug 2012, 12:00

Category

Programming

Tags

  • Bash 1

Connect with me on...

Powered by: Pelican Theme: Elegant