[Top][All Lists]

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

Re: Bug: Bash forgets sourcefile and linenumber of read-in functions

From: L A Walsh
Subject: Re: Bug: Bash forgets sourcefile and linenumber of read-in functions
Date: Mon, 04 Mar 2019 15:44:41 -0800
User-agent: Thunderbird

On 3/4/2019 6:16 AM, Chet Ramey wrote:
> 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? 
from the manpage:
    "output generated when set -x is  enabled"

Earlier, I shared a setting of PS4 that showed the behavior:

export PS4='>${BASH_SOURCE:+${BASH_SOURCE/$HOME/\~}}'\

also from the manpage:
PS4  The value of this parameter is expanded  as  with  PS1  and  the
     value  is  printed  before  each command bash displays during an
     execution trace. ...

FWIW, the other day, I asked where 'function tracing' and 'error tracing'
were defined (under the 'extdebug' option under 'shopt' in manpage). I'm
still not sure what they mean (side info: I only know what execution tracing
is. I don't know if it is the same or different than function or error

In general, in the domain of "computer terminology", 'tracing'
means displaying each line of source just before it is executed.
Do you know of any other definition in the "knowledge domain"
or subject of "bash shell scripting" ?  :-)


> If I add these lines to prog.sh:
_After_ lib.sh has been sourced (I have several functions defined and
exported at login), run prog.sh.  sourcing lib.sh from prog.sh won't
duplicate the problem.


reply via email to

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