Thank You Thorsten,

I hoped, it would be obvious that this is a bug and mksh could be fixed.
It is strange, that mksh lets me define an exit trap without error, but then ignores the trap.
But things seem not to be so easy.

I think the use case of the "subshell_exit" is obvious.
But I will describe it in one sentence, to explain, why I think this bug matters.
The use case: If a subshell does something, that requires a temporary file,
it should also define an EXIT trap, to make sure the temporary file is deleted,
if the script ends unexpected.

The problem is, I see no easy workaround.
So this means for me, I will not support mksh in my library.

If you think this bug does not help to improve mksh, it's probably the best if you close the bug.

Thank you for your help. You have also added some other shells to your tests, that I did not try before.
And I will try to support some of those shells instead of mksh.

Regards
Bernd


Zitat von Thorsten Glaser <t...@mirbsd.de>:

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


Attachment: binSUznWKU4Zn.bin
Description: Öffentlicher PGP-Schlüssel

Reply via email to