bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange change between bash-3.2 and bash-4.0


From: Chet Ramey
Subject: Re: Strange change between bash-3.2 and bash-4.0
Date: Tue, 10 Feb 2009 09:21:23 -0500
User-agent: Thunderbird 2.0.0.19 (Macintosh/20081209)

Roman Rakus wrote:
> Hi
> there is simple script:
> #!/bin/sh
> echo foo|cat /nosuchfile
> echo "here: $?"
> 
> executed by sh -e
> In bash-3.2 we got:
> cat: /nosuchfile: No such file or directory
> 
> but in bash-4.0:
> cat: /nosuchfile: No such file or directory
> here: 1

The bash-4.0 behavior is correct; the previous behavior was a bug.

> From execute_cmd.c:
> 
> /* 10/6/2008 -- added test for pipe_in and pipe_out because they indicate
> the presence of a pipeline, and (until Posix changes things), a
> pipeline failure should not cause the parent shell to exit on an
> unsuccessful return status, even in the presence of errexit.. */
> 
> I'm not sure what Posix says

Posix says that only simple command failure should cause the shell to exit,
with several exceptions that are listed in the standard.  A pipeline is
not a simple command.

That means that a pipeline failure doesn't cause the shell to exit, and
the failure of any individual simple command within a pipeline should not
cause the parent shell to exit.  Even if the child process running the
pipeline element inherits the errexit flag, the fact that it exits should
not affect the parent shell.  (The bug was that only a non-zero exit status
in the *final* pipeline element caused the parent shell to exit.)

> but it breaks the:
> -e  Exit immediately if a command exits with a non-zero status.

I'm not immediately sure where you got that, but the documentation makes
it clear:

         -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 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.


Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer

Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]