bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug when trapping exit from subshell


From: Mark Ferrell
Subject: Bug when trapping exit from subshell
Date: Fri, 16 May 2014 09:41:08 -0700

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"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]