我正在玩bash来绕过这个夏天的下午炎热,突然间我有一个神秘的结果,我无法确定它的起源.
让我解释一下.
我正在使用陷阱ERR来为我的bash脚本创建一些调试功能.
这是运行良好的脚本:
traperror () {
local err=$? # error status
local line=$1 # LINENO
[ "$2" != "" ] && local funcstack=$2 # funcname
[ "$3" != "" ] && local linecallfunc=$3 # line where func was called
echo "<---"
echo "ERROR: line $line - command exited with status: $err"
if [ "$funcstack" != "" ]; then
echo -n " ... Error at function ${funcstack[0]}() "
if [ "$linecallfunc" != "" ]; then
echo -n "called at line …Run Code Online (Sandbox Code Playgroud)