Hi there,

Yesterday, I was extensively using traps with mksh and I noticed something 
unexpected.
Let's consider the following example, from the book "Learning the Korn shell, 
2nd
edition", on this page : https://docstore.mik.ua/orelly/unix3/korn/ch09_01.htm


function func {
    trap 'print "exiting from the function"' EXIT
    print 'start of the function'
}

trap 'print "exiting from the script"' EXIT
print 'start of the script'
func


With mksh (R57 & R58), the "global" trap defined outside the function is never
triggered, as if the trap from function inhibits it :

$ print $KSH_VERSION
@(#)MIRBSD KSH R58 2020/03/27
$ mksh testtrap
start of the script
start of the function
exiting from the function

With ksh93 :

$ print $KSH_VERSION
Version A 2020.0.0
$ ksh testtrap
start of the script
start of the function
exiting from the function
exiting from the script

>From the mksh manpage, we can read this paragraph :

A separate trap/signal environment will be used during the execution
of functions. This will mean that traps set inside a function will
not affect the shell's traps

Could you tell me if I missed something ?

Thanks for your help and take care.

Regards
Ypnose

Reply via email to