bug-bash
[Top][All Lists]
Advanced

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

ERR trap fired in && compound inside a function


From: Yury Kartynnik
Subject: ERR trap fired in && compound inside a function
Date: Sat, 16 Dec 2017 16:15:19 +0300

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-unknown-linux-gnu'
-DCONF_VENDOR='unknown'
-DLOCALEDIR='/home/kartynnik/.local/share/locale' -DPACKAGE='bash'
-DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -g -O2
-Wno-parentheses -Wno-format-security
uname output: Linux zedbook 4.10.0-40-generic #44~16.04.1-Ubuntu SMP
Thu Nov 9 15:37:44 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-unknown-linux-gnu

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



reply via email to

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