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 [email protected] http://cnswww.cns.cwru.edu/~chet/