Is there a simple way to pass information from a subshell back to its
I've run across this problem working on a de* for bash,
(http://www.veryComputer.com/) but the problem exists for any shell
language that has subshells. De* routines live in the same
environment as the debugged program - de*s want access to the
debugged program's environment, and this not only the simplest, but in
some cases only way to get this. The debugged program may be stopped
inside a subshell, but generally one wants to think of the de*
having global scope. So for example if I set a breakpoint or set the
number of lines to list in a display while in a subshell, that setting
should persist when I leave the subshell.
I have had to extended bash just to *know* that it is in a subshell.
This is done a new dynamic variable BASH_SUBSHELL. I have a somewhat
awkward mechanism, of writing to a file the state changes to be passed
back to the parent shell when the program/de* is in a
subshell. But then there is next the problem of having the parent pick
up this information. A first-cut idea that *almost* works is to have
the de* always look for a file from the next level subshell, read
that in and then erase it. Two complications with this. Consider
( (cd a ) ; (cd b ) )
The "cd a" and "cd b" are both at the same subshell level, 2, but they
are in at *different* subshells and from a stepping or tracing
standpoint one follows the other without an action in subshell level
1. A simple subshell check of 2 would not be enough for a de* to
know that the subshell 2 of before was different from this
one. Perhaps the PID could be used to determine this. The second
problem is that at the end of that we jump from subshell level 2 to
subshell level 0. So not only would you have to check for my subshell
level+1 but *all* levels greater than mine.
Again for bash, I've started implementing in bash another fake trap
(like DEBUG, or ERR) called SUBEXIT which runs when leaving a
subshell. However right now, there are technical problems with it. It
would be great if a new mechanism were not needed.
It occurs to me this problem of passing information from a subshell to
its parent is not really unique to de*s. A general mechanism
would be useful. Perhaps it already exists and others have found ways
to do this.