Bash Tip: Exit on Error
Back in my post Your Next Programming Language I mentioned I would post occassional tips about bash scripting. As soon as I started writing my next script, it occured to me: the first thing I always do when writing a new bash script is set the errexit option:
This option makes your script bail out when it detects an error (a command exiting with a non-zero exit code). Without this option the script will plough on, and mayhem often ensues. In all the noise generated it can be a pain to found the root cause of the problem. So I make it a rule to set this option and fail as early as possible.
—
Into continuous integration? Want to be? Try pulse.
This entry was posted on Wednesday, May 24th, 2006 at 1:37 pm and is filed under Bash, Project Automation, Technology. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.











September 24th, 2009 at 4:52 am
Thank you for this tip. Very helpful
August 3rd, 2011 at 4:31 am
Thanks for taking a minute to post this tip — I’m embarrassingly n00bish about shell scripting but have to maintain some build scripts, and was trying to figure out how to do this so I don’t miss errors. Fortunately I composed a good enough google search that your post came up in 2nd place and saved my day.
September 24th, 2011 at 6:42 am
great tip – thanks
October 22nd, 2011 at 1:52 am
Thanks it helps a lot !!!!