On 3/3/19 9:53 PM, L A Walsh wrote:
> In bash 4.4.12, if I have some 'library' like functions that I
> read in at login time, and then later call them -- under trace
> or under bashdb, no source is shown, as bashdb (and for trace, bash)
> doesn't seem to be able to retrieve the original source file name and
> line number where the function was defined.
>
> I'm attaching/including 2 files that demonstrate this:
> The first I will call 'lib.sh' that is sourced from my
> /etc/profile and my /etc/bashrc if bashrc can't find the
> function.
>
> ---'lib.sh'---
> #!/bin/bash
> # add numbers passed in and print result to stdout
> addnums() {
> declare -i sum=0
> while (($#)); do
> [[ $1 =~ [-0-9]+ ]] || return -1
> sum+=$1; shift
> done
> printf "%d\n" "$sum"
> return 0
> }
> declare -fxr addnums
>
>
> ---'prog.sh'---
> #!/bin/bash
> # prog: calls addnums on each line read from stdin
> while read ln; do
> addnums $ln
> done
> ---------------
>
> After lib.sh has been sourced, then either trace prog.sh
> or try bashdb and single stepping through 'addnums'.
What does `trace' mean here? If I add these lines to prog.sh:
echo $BASH_VERSION
. ./lib.sh
declare -F addnums
I get
4.4.23(7)-release
addnums 3 ./lib.sh
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU [email protected] http://tiswww.cwru.edu/~chet/