Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Request: a way to get the subshell level nesting



Thanks for the information. Alas, I don't believe this is does what is needed.

Here is output from no subshell nesting, one subshell, and then two:

$ for i in 1; do if [[ x == x ]]; then print -P %_ ; fi; done
for then
$ (for i in 1; do if [[ x == x ]]; then print -P %_ ; fi; done)
for then
$ ( (for i in 1; do if [[ x == x ]]; then print -P %_ ; fi; done) )
for then
 
In all cases I get the same output with no indication in the last two cases that they are inside one or two subshells.



On Fri, Sep 5, 2008 at 3:49 PM, Phil Pennock <zsh-workers+phil.pennock@xxxxxxxxxxxx> wrote:
On 2008-09-05 at 10:11 -0400, Rocky Bernstein wrote:
> It would be great if there were a way to get the subshell level nesting. ksh
> uses .sh.level and bash BASH_SUBSHELL.

I don't think zsh has that directly as a variable, but it does have %_
for prompt substitution, producing on stdout a list of words identifying
the nested parser states.  It's output text, not a data structure
internal to the shell (so not an array).

zsh% for i in 1; do if [[ x == x ]]; then print -P %_ ; fi; done
for then
zsh%

Of course, capturing that in $(...) will add a cmdsubst to the end.

-Phil



Messages sorted by: Reverse Date, Date, Thread, Author