This Bash script behaves as expected.
test_this.sh
function run_this() {
trap "echo TRAPPED" EXIT
false
echo $?
}
run_this
It prints
1
TRAPPED
However, when I try to export this function, it fails to trap.
test_this2.sh
function run_this() {
trap "echo TRAPPED" EXIT
false
echo $?
}
export -f run_this
Source this at the command line and run it:
> source test_this2.sh
> run_this
Results in
1
Where did the trap go?