Package: bash Version: 5.0-4 Severity: normal Tags: upstream Dear Maintainer,
In a bash script I want to display the actual trap EXIT definition. But in a subshell not the trap definition of the subshell, but of the main script is displayed. To show the problem I use the script trap_handling: set -u set -e f1() { echo "f1: show trap:" >&2 trap >&2 } f2() { trap "/bin/echo f2" EXIT } trap "/bin/echo main" EXIT echo "f1 output: <$(f1)>" echo "f2 output: <$(f2)>" To start the script I use the script test.trap_handling which also tests other shells: #!/bin/sh for i in "busybox sh" bash dash mksh posh; do echo "--- $i ---" eval "/bin/$i ./trap_handling" done The output of this is: --- busybox sh --- f1: show trap: f1 output: <> f2 output: <f2> main --- bash --- f1: show trap: trap -- '/bin/echo main' EXIT f1 output: <> f2 output: <f2> main --- dash --- f1: show trap: f1 output: <> f2 output: <f2> main --- mksh --- f1: show trap: f1 output: <> f2 output: <f2> main --- posh --- f1: show trap: f1 output: <> f2 output: <> main As you can see bash displays the wrong trap in the subfunction f1. But it correctly does not execute it, when leaving f1. A trap defined in f2 is correctly executed. So it seems only to be a problem of displaying the trap. -- System Information: Debian Release: buster/sid APT prefers testing APT policy: (500, 'testing') Architecture: amd64 (x86_64) Kernel: Linux 4.19.0-5-amd64 (SMP w/1 CPU core) Locale: LANG=en_US, LC_CTYPE=en_US (charmap=ISO-8859-1), LANGUAGE=en_US (charmap=ISO-8859-1) Shell: /bin/sh linked to /usr/bin/dash Init: systemd (via /run/systemd/system) Versions of packages bash depends on: ii base-files 10.1 ii debianutils 4.8.6.1 ii libc6 2.28-10 ii libtinfo6 6.1+20181013-2 Versions of packages bash recommends: ii bash-completion 1:2.8-6 Versions of packages bash suggests: pn bash-doc <none> -- no debconf information