bug-bash
[Top][All Lists]
Advanced

[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 <address@hidden>:

     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 address@hidden
     [2]http://tiswww.cwru.edu/~chet/

   --
   Sent from Yandex.Mail for mobile

References

   1. mailto:address@hidden
   2. http://tiswww.cwru.edu/~chet/


reply via email to

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