[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ERR trap fired in && compound inside a function
From: |
yury |
Subject: |
Re: ERR trap fired in && compound inside a function |
Date: |
Sat, 16 Dec 2017 18:15:56 +0300 |
Ah, pardon me, you're right. But I would expect $BASH_COMMAND inside
the trap handler be 'f' in this case.
18:01, 16 �нежн� 2017, Chet Ramey <chet.ramey@case.edu>:
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 [1]chet@case.edu
[2]http://tiswww.cwru.edu/~chet/
--
Sent from Yandex.Mail for mobile
References
1. mailto:chet@case.edu
2. http://tiswww.cwru.edu/~chet/