[Top][All Lists]

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

Re: Problem with overridden functions and BASH_SOURCE Array

From: Chet Ramey
Subject: Re: Problem with overridden functions and BASH_SOURCE Array
Date: Thu, 15 Dec 2011 20:44:23 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:8.0) Gecko/20111105 Thunderbird/8.0

On 12/14/11 4:13 AM, dethrophes@modt005 wrote:

> Bash Version: 4.2
> Patch Level: 8
> Release Status: release
> Description:
>       Problem with overridden functions having wrong source file name in 
>       see example in Repeat-By section

This is an interesting problem.  The line number and source file name
information is set when the function is read instead of when it's
defined (defining a function is a command itself).  Since the source
command and the function redefinition are part of the compound command
that is the `if' command's body, the entire if command is read, setting
the initial function filename and line number information, before any of
it is executed.  That gets overwritten when the second file is sourced,
and not restored when the function is redefined during the if command's

The difference between main1 and main2 is the fact that bash always reads
an entire command before executing any of it, and the if statement is a
compound command.

I will have to see if the function definition can do a better job of
carrying around the source file and line information, but that's a pretty
significant change.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/

reply via email to

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