bug-bash
[Top][All Lists]
Advanced

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

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


From: Konstantin Andreev
Subject: Subshell exit trap is not invoked if shell exit trap also set
Date: Mon, 25 Mar 2019 22:48:05 +0300
User-agent: Mozilla/5.0 (X11; SunOS i86pc; rv:31.0) Gecko/20100101 Thunderbird/31.6.0

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.

Verified on:

    Solaris 11.3, bash 4.1.17(1)-release (i386-pc-solaris2.11)
    CentOS Linux 7.2.1511, bash 4.2.46(1)-release (x86_64-redhat-linux-gnu)
    CentOS Linux 7.2.1511, bash 5.0.0(1)-release (x86_64-pc-linux-gnu)

Best regards,
Konstantin Andreev



reply via email to

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