Is there a way to configure the running of a bash script so that
any error will cause the entire script to exit (with an appropriate
non-zero exit status)? I.e., to make something like this
#!/bin/bash
command1
command2 || command3
command4 ; command5 ; command6
# ...
commandN
exit 0
behave *as if* it were written like this
#!/bin/bash
command1 && \
( command2 || command3 ) && \
command4 && command5 && command6 && \
# ...
commandN && \
exit 0
without cluttering the code with all those '&&'s and backslashes?
TIA,
jill
--
To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
> Is there a way to configure the running of a bash script so that
> any error will cause the entire script to exit (with an appropriate
> non-zero exit status)? I.e., to make something like this
set -e
From the man page:
-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 an until or
while loop, part of an if statement, part of a && 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.
--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
> Is there a way to configure the running of a bash script so that
> any error will cause the entire script to exit (with an appropriate
> non-zero exit status)?
You can put ... || exit $? after each command.
Some shells, like zsh, have a facility for trapping on any command
failure, allowing you to do something whenever a command fails,
including exiting.
--
__ Erik Max Francis && m...@alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
\__/ Life is a gamble so I should / Live life more carefully
-- TLC
>In article <c9dtnl$j1q$1...@reader2.panix.com>,
> J Krugman <jkrug...@yahbitoo.com> wrote:
>> Is there a way to configure the running of a bash script so that
>> any error will cause the entire script to exit (with an appropriate
>> non-zero exit status)? I.e., to make something like this
>set -e
>From the man page:
> -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 an until or
> while loop, part of an if statement, part of a && 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.
That's just the ticket! Many thanks!