set -e (was: RHEL-CentOS conversion scripts (was Re: apache?))
Kevin D. Clark
kevin_d_clark at comcast.net
Fri Apr 10 13:47:52 EDT 2009
Alan Johnson writes:
> At first, my scripting may be a bit confusing because I am very verbose for
> debuggin purposes, and I expect this kind of script is always going to need
> debugging. You will see each command echoed before it is executed in an if
> statement so that it only conitues to the next command if each previous is
> successful (I hate the over use of && to run commands).
I have not looked at your scripts, but this reminds me of one of the
things that I am enthusiastic about: "set -e" in shell scripts.
Here is the Bash documentation for "set -e":
-e Exit immediately if a simple command (see SHELL GRAMMAR
above) exits with a non-zero status. The shell does not
exit if the command that fails is part of the command
list immediately following a while or until keyword,
part of the test in an if statement, part of or
list, or if the command's return value is being inverted
via !. A trap on ERR, if set, is executed before the
shell exits.
I frequently write industrial strength shell scripts, and I nearly
always put "set -e" at the top. I would humbly suggest for those
people on this list who are not experts at creating shell scripts that
they begin all of their shell scripts like this:
#!/bin/sh
set -e
In my experience, configuring things this way (and being forced to
deal with the ramifications of this) leads to higher quality code.
Regards,
--kevin
--
GnuPG ID: B280F24E God, I loved that Pontiac.
alumni.unh.edu!kdc -- Tom Waits
http://kdc-blog.blogspot.com/
More information about the gnhlug-discuss
mailing list