On 12/16/17 8:15 AM, Yury Kartynnik wrote:

> Bash Version: 4.4
> Patch Level: 12
> Release Status: release
> 
> Description:
>         ERR trap gets fired when a non-last command in a && compound
> command inside a function returns a non-zero code.
>         This doesn't happen when the compound command is executed
> directly from the shell.
>         According to the trap documentation, non-last commands in &&
> and || should not fire the ERR trap in any case.
> 
> Repeat-By:
>         $ on_error() {
>         > echo "Error $? in $@" >&2
>         > }
>         $ trap 'on_error $BASH_COMMAND' ERR
>         $ false
>         Error 1 in false
>         $ # ^^^ works as intended
>         $ false && true
>         $ # ^^^ doesn't fire, complies with the docs
>         $ f() {
>         > false && true
>         > }
>         $ f
>         Error 1 in false
>         $ # ^^^ fires, doesn't comply with the docs

The ERR trap fires because `f' returns 1, the return status of the last
command executed in the function body.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://tiswww.cwru.edu/~chet/

Reply via email to