bug-bash
[Top][All Lists]
Advanced

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

Re: BASH_SUBSHELL count not counting?


From: Dennis Williamson
Subject: Re: BASH_SUBSHELL count not counting?
Date: Mon, 29 Aug 2011 19:47:08 -0500

On Mon, Aug 29, 2011 at 7:24 PM, Roger <rogerx.oss@gmail.com> wrote:
>
> Within GNU Screen session & VTE:
>
> roger@localhost2 ~ $ bash
>
> 0 ;-)
> roger@localhost2 ~ $ ps -ax |tail
> Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html
> 30840 pts/6    Ss     0:00 /bin/bash - /home/roger/bin/bashnoprofile_ionice.sh
> 30842 pts/5    S+     0:00 bash --noprofile
> 30844 pts/7    Ss+    0:00 su -
> 30845 pts/6    S      0:00 bash --noprofile
> 30848 pts/8    Ss     0:00 /bin/bash - /home/roger/bin/bashnoprofile_ionice.sh
> 30849 pts/8    S+     0:00 bash --noprofile
> 30920 ?        S      0:00 [kworker/1:2]
> 30981 pts/6    S      0:00 bash <-- New bash shell within a bash shell
> 30995 pts/6    R+     0:00 ps -ax
> 30996 pts/6    S+     0:00 tail
>
> 0 ;-)
> roger@localhost2 ~ $ echo $BASH_SUBSHELL
> 0
>
> 0 ;-)
> roger@localhost2 ~ $ exit
> exit
>
> 0 ;-)
> roger@localhost2 ~ $
>
> --
> Roger
> http://rogerx.freeshell.org/
>
>

I think you want $SHLVL

$ echo $SHLVL $BASH_SUBSHELL
1 0
$ bash
$ echo $SHLVL $BASH_SUBSHELL
2 0
$ (echo $SHLVL $BASH_SUBSHELL)
2 1
$ ( (echo $SHLVL $BASH_SUBSHELL) )
2 2
$ echo $SHLVL $(echo "$BASH_SUBSHELL")
2 1
$ echo foo | while read -r bar; do echo $SHLVL $BASH_SUBSHELL; done
2 1
$ while read -r bar; do echo $SHLVL $BASH_SUBSHELL; done < <(echo foo)
2 0


-- 
Visit serverfault.com to get your system administration questions answered.



reply via email to

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