Bernd Schumacher dixit: >Please confirm, that this is a bug and not the expected behaviour of mksh.
I still cannot confirm either way, but some preliminary research with an extended test script: $ cat script fkt() { trap -- "echo $1 >&2" EXIT } fkt shell_exit $(fkt fn_exit) $(trap -- "echo comsub_exit >&2" EXIT) (trap -- "echo subshell_exit >&2" EXIT) $ mksh script shell_exit $ bash2.05b script subshell_exit shell_exit $ ksh93 script fn_exit comsub_exit subshell_exit shell_exit $ bash4 script fn_exit comsub_exit subshell_exit shell_exit $ nbsh script fn_exit comsub_exit subshell_exit shell_exit $ dash script fn_exit comsub_exit subshell_exit shell_exit $ yash script fn_exit comsub_exit subshell_exit shell_exit $ zsh script shell_exit fn_exit comsub_exit subshell_exit $ zsh --emulate sh script fn_exit comsub_exit subshell_exit shell_exit With the addition of subshell_exit (I renamed yours in fn_exit), it’s consistent with no other shell I have, not even GNU bash 2.05b (Heirloom Shell doesn’t know of the EXIT trap, and I’m ignoring the C shell). zsh is a notable outlyer but easily fixed. The manual page has something to say about EXIT traps defined in functions declared using “function foo { … }” (Korn Shell syntax), but that’s not used here. I think that I’ll adapt it to the other shells independent of whether it’s really a bug or not, for the sake of consistency. If you’re still interested in semantics, I can continue the research, though. bye, //mirabilos -- “It is inappropriate to require that a time represented as seconds since the Epoch precisely represent the number of seconds between the referenced time and the Epoch.” -- IEEE Std 1003.1b-1993 (POSIX) Section B.2.2.2