bug-bash
[Top][All Lists]
Advanced

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

Re: RETURN trap will inherit last RETURN trap cmd though set +T


From: Chet Ramey
Subject: Re: RETURN trap will inherit last RETURN trap cmd though set +T
Date: Wed, 23 Jan 2019 15:20:57 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.4.0

On 1/23/19 10:59 AM, Shen Herbert wrote:
> Configuration Information [Automatically generated, do not change]:
> Machine: x86_64
> OS: linux-gnu
> Compiler: gcc
> Compilation CFLAGS: -march=x86-64 -mtune=generic -O2 -pipe 
> -fstack-protector-strong -fno-plt 
> -DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/bin' 
> -DSTANDARD_UTILS_PATH='/usr/bin' -DSYS_BASHRC='/etc/bash.bashrc' 
> -DSYS_BASH_LOGOUT='/etc/bash.bash_logout' -DNON_INTERACTIVE_LOGIN_SHELLS 
> -Wno-parentheses -Wno-format-security
> uname output: Linux arch.ishbguy.org 4.20.3-arch1-1-ARCH #1 SMP PREEMPT Wed 
> Jan 16 22:38:58 UTC 2019 x86_64 GNU/Linux
> Machine Type: x86_64-pc-linux-gnu
> 
> Bash Version: 5.0
> Patch Level: 0
> Release Status: release
> 
> Description:
> 
> RETURN trap will inherit last RETURN trap cmd though set +T under bash 5.0 or 
> bash 4.4, however, this will not happen under bash 4.3. For example:
> ```
> set +T
> one { trap 'echo in one' RETURN; }
> all {
>     trap 'echo in all' RETURN
>     one
> }
> all
> ```
> in bash 5.0 and 4.4 will print:
> ```
> in one
> in one
> ```
> in bash 4.3 will print:
> ```
> in one
> in all
> ```

There is only a single RETURN trap; traps are not local. If a called
function sets the RETURN trap, it should overwrite the caller's trap,
and the caller's value should not get restored. Then, when the caller
returns, and there is a RETURN trap set, it should execute the current
RETURN trap, not the one it had before it called the second function
(`one' in this case).

The behavior of bash-4.3 was a bug. I changed it partly as the result of
this bug report:

http://lists.gnu.org/archive/html/bug-bash/2015-08/msg00130.html

This change made the behavior of the RETURN trap align with the DEBUG and
ERROR traps.

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



reply via email to

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