Consider this:
bash <<EOF
foo() {
trap 'echo exit' EXIT
}
foo &
EOFAfter trap is set, the subshell exits and `echo exit` should be run, but it won't. If you set a RETURN trap instead it works though. This is reproducible on bash4 and bash5 -- Oğuz
