[ale] bash question

Alexander Barton abarton at mindspring.com
Sun Mar 26 15:02:20 EST 2006


David Corbin wrote:
> I right my share of shell scripts, and I know how to check for the status of 
> one command and terminate the script.
> 
> I was wondering if there is a an option to bash to have it quit the script 
> automatically when a command returns a non-zero status.  It would make some 
> scripts much cleaner.

You want in your script something like

	#!/bin/bash -e

or

	#!/bin/bash
	set -e

If I remember correctly, -e causes the script to exit with non-zero 
status as soon as a command returns non-zero.  There are some 
exceptions, like when the command is in a conditional expression.  Read 
the bash man page for sure.  Also, there are a few gotchas, like when 
grep returns non-zero on error, but also when no matching lines are found.

-Alexander



More information about the Ale mailing list