bug-bash
[Top][All Lists]
Advanced

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

Re: Subshell exit trap is not invoked if shell exit trap also set


From: Chet Ramey
Subject: Re: Subshell exit trap is not invoked if shell exit trap also set
Date: Tue, 26 Mar 2019 09:57:15 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.6.0

On 3/25/19 3:48 PM, Konstantin Andreev wrote:
> Consider the simple `ssxtrap' script:
> 
> | #!/bin/bash
> |
> | echo  ext pid=$BASHPID
> | # trap 'echo "ext exit trap in $BASHPID"' EXIT
> |
> | (echo int pid=$BASHPID
> | trap 'echo "int exit trap in $BASHPID"' EXIT
> | sleep 99999) &
> |
> | wait
> | echo "subshell done"
> 
> Let's run it:
> 
> Terminal A                             Terminal B
> ----------                             -----------
> | $ ./ssxtrap
> | ext pid=10370
> | int pid=10371
>                                        | $ kill 10371
> | int exit trap in 10371
> | ./ssxtrap: line 10: 10371 Terminated ...
> | subshell done
> 
> ... but if I uncomment the line that installs exit trap in the main shell,
> the output changes to:
> 
> Terminal A                             Terminal B
> ----------                             -----------
> | $ ./ssxtrap
> | ext pid=10373
> | int pid=10374
>                                        | $ kill 10374
> | ./ssxtrap: line 10: 10374 Terminated ...
> | subshell done
> | ext exit trap in 10373
> 
> i.e. subshell exit trap is not invoked anymore.
> 
> Since subshell exit trap shall not depend from main shell exit trap, this
> behaviour looks like a bug for me.

I can't reproduce this using RHEL 7 or Mac OS X using bash-5.0.3.

-- 
``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]