Re: How: exit on error?

From: Barry Margolin (barmar_at_alum.mit.edu)
Date: 05/31/04


Date: Sun, 30 May 2004 20:29:12 -0400

In article <c9dtnl$j1q$1@reader2.panix.com>,
 J Krugman <jkrugman345@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.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


Relevant Pages

  • Re: dd command & reading in background
    ... ^ D,"UnixReview: Shell Corner: The dspl Korn Shell ... user input timeout, do a search on C.U.S. for the ... # 0<c<127 - job exited with this exit code ...
    (comp.unix.shell)
  • Re: Most dependable way to run system commands
    ... Eventually I'd like to bring the execution of a few system commands ... specific execution issue (it dealt more with executing Perl code)). ... Unix and many similar systems, the exit status is an integer, with 0 ... variable after running a command via system or backticks. ...
    (perl.beginners)
  • Re: very slow cursor in CMD window w/Text editor?
    ... REM MS-DOS-based application, Windows runs COMMAND.COM. ... To run CMD.EXE, the Windows command prompt, ... The exit command is an internal command part of command.com or cmd.exe. ...
    (microsoft.public.windowsxp.general)
  • Re: difference between the -o and || conditionals.
    ... you are running a first "[" command with ... equal to the number whose string representation is in its third ... a non-0 exit status otherwise. ... the cat and grep commands are run and its (possibly ...
    (comp.unix.shell)
  • Re: [BUGFIX 2/2] gdth: bugfix for the Timer at exit crash
    ... I have more problems reported, with exit, and am just sending one more patch that puts ... What does a driver need to do if it needs a consistent shutdown retine? ... The alternative for GDTH would be to process the SCSI SYNCHRONIZE CACHE ... Why would we think that the controller does not support this command ...
    (Linux-Kernel)