[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ale] bash question
- Subject: [ale] bash question
- From: abarton at mindspring.com (Alexander Barton)
- Date: Sun, 26 Mar 2006 15:02:20 -0500
- In-reply-to: <[email protected]>
- References: <[email protected]>
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