the exit handler is called, you just muted it. remove the redirections, and you'll also notice you need a space after your !
On 16 May 2014 12:41, Mark Ferrell <ma...@homeonderanged.org> wrote: > The following script properly reports the exit code to the calling > environment, , but the exit handler is not called if a function > triggers the exit vs an external command. > > Script executed via: > bash <script> false;echo $? > bash <script> /bin/false;echo $? > > Expected the function 'exit_handler()' to be called in both cases. > When using bash, exit_handler() was only called in the '/bin/false' case. > > Note: this behaviour is only seen in bash (tested on 4.1.2 on CentOS > 6.5 and 4.2.25 on Ubuntu 12.04). The following shells where also > tested and all behaved as expected (i.e. the exit handler was called): > ksh, dash, BusyBox's ash, and zsh. > > Script: > set -e > exit_handler() { echo "exit code: $?"; } > false() { !:; } > > main() > {( > trap exit_handler 0 > "$@" >> /dev/null 2>&1 > )} > main "$@" > echo "after main" > >