The trap EXIT not allways executed, see example script
Repeat-By:
Example script
----------------------------------------------------------------
#!/bin/bash
bash -c '
_rm () { echo ATT: Execute trap function; }
trap _rm EXIT
rm -f doesnotexist
'
echo $?
bash -c '
_rm () { echo ATT: Execute trap function; }
rm -f doesnotexist
trap _rm EXIT
'
echo $?
----------------------------------------------------------------
which results in
----------------------------------------------------------------
0
ATT: Execute trap function
0
----------------------------------------------------------------