bug-bash
[Top][All Lists]
Advanced

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

Re: When exactly it is possible to modify BASH_LINENO variable?


From: Chet Ramey
Subject: Re: When exactly it is possible to modify BASH_LINENO variable?
Date: Wed, 03 Dec 2014 10:23:52 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:24.0) Gecko/20100101 Thunderbird/24.6.0

On 12/3/14, 4:48 AM, Adam Ryczkowski wrote:
> I am trying to write a function that logs execution of the *next* line. The
> usage would be:
> 
>     #/bin/bash
>     log=/tmp/mylog.log
>     var1="some variable"
> 
>     log
>     echo "Unfortunately this line gets executed twice" | tee -a
> /tmp/temp/bla-bla.tmp
> 
> The problem is that I can't reliably get to modify `BASH_LINENO[0]`. I
> swear, that I used to have success in it, but now everytime I change its
> value (both inside or outside the function body) the assignment gets
> ignored. Is there any way to get the bash to skip execution of the next line?

BASH_LINENO is a call stack; assignments to it should be (and are) ignored.
That's been the case since at least bash-3.2 (that's where I quit looking).

There is an indirect way to force bash to not execute the next command:
set the `extdebug' option and have the DEBUG trap return a non-zero status.

Chet

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



reply via email to

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