@ page 2358 line 74545 section 2.14 objection [gwc set -e]
Problem:
Edition of Specification (Year): 2008
Defect code : 1. Error
The description of set -e does not match existing practice in
several respects, as discussed at length on the austin-group-l
mailing list in threads beginning 2009-02-10 ("error handling in
shell pipelines") and 2009-02-17 ("set -e description").
The new description of set -e proposed below is taken from the
minutes of the March 12th teleconference, with a few minor changes:
* shallification
* changed "!" to "the ! reserved word"
* changed "2.8.1" to "[xref to 2.8.1]"
* changed "AND or OR list" to "AND-OR list"
and the two major changes, related to pipelines and functions,
discussed in replies to the minutes.
I have also added the fix to 2.9.2 identified during the original
discussion, and some application usage and rationale.
Action:
Replace the description of -e with:
-e When this option is on, when any command fails (for any of the
reasons listed in [xref to 2.8.1] or by returning an exit status
greater than zero) the shell immediately shall exit with the
following exceptions:
1) The failure of any individual command in a multi-command
pipeline shall not cause the shell to exit. Only the
failure of the pipeline itself shall be considered.
2) The -e setting shall be ignored when executing the compound
list following the while, until, if, or elif reserved word,
a pipeline beginning with the ! reserved word, or any
command of an AND-OR list other than the last.
3) If the exit status of a compound command other than a
subshell command was the result of a failure while -e was
being ignored, then -e shall not apply to this command.
This requirement applies to the shell environment and each
subshell environment separately. For example, in
set -e; (false; echo one) | cat; echo two
the false command causes the subshell to exit without executing
echo one; however, echo two is executed because the exit status
of the pipeline (false; echo one) | cat is zero.
When a function is executed, the effect of -e on the commands
within the function body shall be as if the function body had
appeared in place of the function name.
In the APPLICATION USAGE for the set builtin utility at
page 2360 line 74631, change "None" to:
Application writers should avoid relying on set -e within
functions. For example, in the following script:
set -e
start() {
some-server
echo some-server started successfully
}
start || echo >&2 some-server failed
the -e setting is ignored within the function body (because the
function is a command in an AND-OR list other than the last).
Therefore if some-server fails, the function carries on to
echo "server started successfully", and the exit status of the
function is zero (which means "server failed" is not output).
In the RATIONALE for the set builtin utility after
page 2361 line 74660, add a new paragraph:
The description of the -e option is intended to match the
behavior of the 1988 version of the KornShell.
At page 2319 line 73188 section 2.9.2, change:
If the reserved word ! does not precede the pipeline, the
to:
If the pipeline does not begin with the ! reserved word, the
|