|
From: R. B. <ro...@pa...> - 2003-08-06 04:02:44
|
Mikael Andersson reports:
> The shell-script below gives the following output in bashdb.
You've found a slight bug in bash 2.05b. I've found several like this
in the past. When I try the following on an unmodified bash 2.05b
#!/bin/bash
trap 'echo $LINENO' DEBUG
s=`(
echo This is
echo not visible
echo while debugging
)`
echo $s #This line should not be displayed until later
# Didn't expect to see me
# And not me either
# Or me either.
The output I get is:
7
8
This is not visible while debugging
I think I have seen this kind of behavior before in other
contexts. What I think is going on is that the parser has to scan to
the to the end of the `( ... )` initially. There is a global variable
inside the parser for the current line number -- that's line 6 in your
example (7 in mine since I added the trap statement). It is not reset
when going into the subshell echo's. After each echo this global
counter is incremented. Here, fortunately, 6+1, and 6+1+1 appear in
comments so you know it's totally bogus. I write "fortunately" because
if it had been real code it would have been extremely confusing.
In other places when I saw I was going inside a subshell, I had to
save an restore this global line counter. I looked in CVS for what I
recall running into with substitutions. I can't find it right now, but
a similar example to give you an idea is between version 1.13 and 1.14
of execute_cmd.c where you have to do the same thing with say a case
statement. The diff you can look at in CVS such as:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/bashdb/bashdb/execute_cmd.c.diff?r1=1.13&r2=1.14&sortby=date
If this guess is correct, we need to find the place this is getting
run and do something similar to what's done with working
substitutions.
Again, alas I don't have much time to investigate further.
|