小编hmo*_*liu的帖子

神秘的LINENO在bash陷阱ERR中

我正在玩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)

bash shell

11
推荐指数
1
解决办法
4415
查看次数

标签 统计

bash ×1

shell ×1