bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

trying to make sense of BASH_LINENO


From: Brian J. Murrell
Subject: trying to make sense of BASH_LINENO
Date: Fri, 20 Mar 2009 11:57:08 -0400

I'm trying to write a "stack trace" function and BASH_LINENO doesn't
make sense sometimes and doesn't appear too accurate at others.

Here's my test script:

shopt -s extdebug
trap 'backtrace' ERR
set -E

backtrace() {

    echo "FUNCNAME: address@hidden"
    echo "BASH_SOURCE: address@hidden"
    echo "BASH_LINENO: address@hidden"
    echo "BASH_ARGV: address@hidden"
    echo "BASH_ARGC: address@hidden"

    echo ${LINENO} ${FUNCNAME[0]} ${BASH_SOURCE[0]}
    echo ${BASH_LINENO[0]} ${FUNCNAME[1]} ${BASH_SOURCE[1]}
    echo ${BASH_LINENO[1]} ${FUNCNAME[2]} ${BASH_SOURCE[2]}
}

false_func() {

    echo "in false_func(), FUNCNAME: address@hidden"
    echo "in false_func(), BASH_LINENO: address@hidden"
    echo "in false_func(), LINENO: ${LINENO}"
    false
    echo "after false"

}

false_func

The output of which is:

$ bash /tmp/bt.sh 
in false_func(), FUNCNAME: false_func main
in false_func(), BASH_LINENO: 28 0
in false_func(), LINENO: 22
FUNCNAME: backtrace false_func main
BASH_SOURCE: /tmp/bt.sh /tmp/bt.sh /tmp/bt.sh
BASH_LINENO: 18 28 0
BASH_ARGV: 
BASH_ARGC: 0 0
13 backtrace /tmp/bt.sh
18 false_func /tmp/bt.sh
28 main /tmp/bt.sh
after false

The BASH_LINENO array has 18 as it's second argument which is the line
number that false_func() is defined on, not the line number in that
function where it left that function for the next one (backtrace by way
of the ERR trap).

Thots?

b.

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]