ERR trap strange behavior (infinite loop) depending on how the function is defined

Hope someone can handle this - not sure if this is a known bug with ksh93?

#!/bin/ksh93
_errorCheck()
{
        LINENO=$1
        print "Error on or near line $LINENO - please check error log"
        exit 1
}
trap '_errorCheck ${LINENO}' ERR

false

      

It means:

 Error on or near line 10 - please check error log

      

However ... if the function is defined with a word function instead of ():

#!/bin/ksh93
function _errorCheck 
{
        LINENO=$1
        print "Error on or near line $LINENO - please check error log"
        exit 1
}
trap '_errorCheck ${LINENO}' ERR

false

      

Then it is issued:

Error on or near line 10 - please check error log
Error on or near line 10 - please check error log
Error on or near line 10 - please check error log
Error on or near line 10 - please check error log
Error on or near line 10 - please check error log
Error on or near line 10 - please check error log

      

What seems like an infinite number of times ...

Can anyone explain this behavior?

As requested: KSH_VER = Version M-12/28 / 93e

+3


source to share


1 answer


You can add the line

trap - ERR

      

at the top of any function before resetting the hook after it was first run.



For me, the second function shows the expected behavior.

Either way, you've experimented and found something that works. That's all that matters.

0


source







All Articles