help-bash
[Top][All Lists]
Advanced

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

Re: Bug that only happens in ubuntu 22.04 even with older bash version


From: Chet Ramey
Subject: Re: Bug that only happens in ubuntu 22.04 even with older bash version
Date: Wed, 10 Aug 2022 09:26:24 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.11.0

On 8/8/22 12:11 PM, Robert E. Griffith wrote:
> Does anyone know how bash 5.0 and 5.1 on ubuntu 22.04(jammy) could behave
> differently from bash 5.0 and 5.1 on  20.04(focal)?

It's probably something in an ubuntu startup file somewhere. Who knows?
But I get the same results you do using bash-5.1. Here's why.

>    2. rarely but repeatedly a DEBUG trap stops updating BASH_COMMAND so
>    that it gets stuck on that command and no longer updates even though
>    its actually executing other script commands. its typically not
>    first command -- its updates for a while and then stops.
        [...]
> Here is the test script that I use to reproduce behavior 2 (BASH_COMMAND
> stops update in the DEBUG trap). I have not yet been able to reproduce the
> behavior 1 (reentering infinite loop) in a small test script.

This is the same change we've been talking about.
> 
>    bobg@focal$ cat ./debugUsr2Trap5.1.sh
>    #!/usr/bin/env bash
>    shopt -s extdebug

This sets debug mode, functrace (-T) and errtrace (-E). In debug mode,
subshells inherit the value of shell options, including extdebug,
functrace, and errtrace (because that's what the debugger needs). If
functrace is enabled, subshells inherit the DEBUG trap.

>    count=8
>    dbgScript='
>        echo "# ENTER DEBUG  ($BASH_COMMAND) (${#FUNCNAME[@]})";
>        ((count--<=0)) && exit
>        if (( ${#FUNCNAME[@]} <3 )); then
>            trap - DEBUG
>            local code=0
>        else
>            local code=2
>        fi
>        (exit $code)

So the subshell inherits debug mode, functrace, error trace, and the
DEBUG trap (because that's what the debugger needs).

Now that the subshell no longer thinks it's running a DEBUG trap, and
DEBUG is still trapped (because of functrace), it runs the DEBUG trap
before running the simple command `exit $code'.

If you don't want subshells to inherit the DEBUG trap, turn off
functrace by adding `set +T' after you enable extdebug.

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



reply via email to

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