希望有人能对此提供帮助 - 不确定这是否是 ksh93 的已知错误?
#!/bin/ksh93
_errorCheck()
{
LINENO=$1
print "Error on or near line $LINENO - please check error log"
exit 1
}
trap '_errorCheck ${LINENO}' ERR
false
这个输出:
Error on or near line 10 - please check error log
但是...如果函数是使用单词 function 而不是 () 定义的:
#!/bin/ksh93
function _errorCheck
{
LINENO=$1
print "Error on or near line $LINENO - please check error log"
exit 1
}
trap '_errorCheck ${LINENO}' ERR
false
然后输出:
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
什么好像是无限次...
谁能解释这种行为?
根据要求: KSH_VER=版本 M-12/28/93e
最佳答案
使用 function f {...}
和 f() {...}
它在 ksh 中实际上是不同的。您可以检查这个答案,它很好地解释了您正在试验的内容。
https://unix.stackexchange.com/questions/73750/difference-between-function-foo-and-foo
关于function - Trap ERR 异常行为(无限循环)取决于函数的定义方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27204466/