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    c...@case.edu    http://tiswww.cwru.edu/~chet/

Reply via email to