调用者0在陷阱处理程序中给出错误的行号

Xen*_*hic 7 bash shell

当使用Bash陷阱功能中内置的调用者时,结果会caller 0给出错误的行号,总是给出1.例如:

#!/bin/bash
function foo {
    exit 1
}
function bar {
    foo
}
function err {
    (( i = 0 ))
    while caller $i; do
        (( ++i ))
    done
}
trap err EXIT
bar
Run Code Online (Sandbox Code Playgroud)

给出以下输出:

1 foo ./test.sh
6 bar ./test.sh
15 main ./test.sh
Run Code Online (Sandbox Code Playgroud)

虽然输出i > 0是正确的,但caller 0在陷阱处理程序中使用时,它似乎总是1作为行号给出.有没有办法从陷阱处理程序中获取失败函数的实际行号?

Jon*_*son 3

这似乎是 3.2.57(1)-release 之后引入的一个错误:

$ bash -version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin14)
Copyright (C) 2007 Free Software Foundation, Inc.

$ bash ./test.sh
3 foo ./test.sh
6 bar ./test.sh
15 main ./test.sh

$ /usr/local/bin/bash --version
GNU bash, version 4.3.30(1)-release (x86_64-apple-darwin14.1.0)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ /usr/local/bin/bash ./test.sh
1 foo ./test.sh
6 bar ./test.sh
15 main ./test.sh
Run Code Online (Sandbox Code Playgroud)

bash 项目似乎已经有一个错误报告。