Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -Wno-parentheses -Wno-format-security uname output: Linux fedora31.localdomain 5.3.11-300.fc31.x86_64 #1 SMP Tue Nov 12 19:08:07 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux Machine Type: x86_64-redhat-linux-gnu
Bash Version: 5.0 Patch Level: 7 Release Status: release Description: When you execute a function in the background, and in that function you set a trap on EXIT, it doesn't get triggered when the function returns. This behavior doesn't seem to be documented anywhere and other shells (zsh, dash, ash) behave differently. Repeat-By: The following script should print: done 1 done 2 cleanup #!/bin/sh cleanup() { wait echo cleanup } do_work() { sleep 2 echo done "$@" } run() { trap cleanup EXIT do_work 1 & do_work 2 & # It does work with explicit exit #exit } run&