bug-bash
[Top][All Lists]
Advanced

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

Re: BASH_SUBSHELL documentation misleading


From: Maarten Billemont
Subject: Re: BASH_SUBSHELL documentation misleading
Date: Wed, 23 Mar 2011 21:29:59 +0100

On 23 Mar 2011, at 21:15, Sam Liddicott wrote:

> 
> On 23/03/11 18:52, Chris F.A. Johnson wrote:
>> 
>> On Wed, 23 Mar 2011, Sam Liddicott wrote:
>> 
>>> 
>>> Configuration Information [Automatically generated, do not change]:
>>> Machine: i686
>>> OS: linux-gnu
>>> Compiler: gcc
>>> Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' 
>>> -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' 
>>> -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DP$ uname output: Linux 
>>> sojo 2.6.35-28-generic-pae #49-Ubuntu SMP Tue Mar 1 14:58:06 UTC 2011 i686 
>>> GNU/Linux
>>> Machine Type: i686-pc-linux-gnu
>>> 
>>> Bash Version: 4.1
>>> Patch Level: 5
>>> Release Status: release
>>> 
>>> Description:
>>>       man page says:
>>> 
>>>       BASH_SUBSHELL
>>>             Incremented by one each time a subshell or subshell environment
>>>             is spawned.  The initial value is 0.
>>> 
>>>       This suggests that:
>>> 
>>>       echo $BASH_SUBSHELL ; ( echo ) ; echo $BASH_SUBSHELL
>>> 
>>>       would not give the same answer for BASH_SUBSHELL
>> 
>>   No, it suggests that:
>> 
>> echo $BASH_SUBSHELL ; ( echo $BASH_SUBSHELL )
>> 
>>   would not give the same answer for BASH_SUBSHELL
> 
> It should suggest that, because that is how it actually works.
> 
> But the man page is misleading and does not actually suggest this.
> 
>> 
>>   In your example, the second "echo $BASH_SUBSHELL" is at the same
>>   depth as the first.
>> 
> 
> Yes. But a new subshell environment has been spawned. Each time that happens 
> BASH_SUBSHELL should increase.
> 
> Of course I know how it does work, but the man page isn't clear. It doesn't 
> say that the increase is only visible within the subshell and therefore it is 
> a measurement of subshell depth.
> 
> Sam
> 

I must concur.  In the bug example at the second expansion of BASH_SUBSHELL 
occurs after "a subshell or subshell environment is spawned".  The 
documentation does not specify that BASH_SUBSHELL is actually unmodified in the 
running shell and merely copied to the subshell and incremented there.  What's 
more, the fact that this is not mentioned, grammatically suggests that 
BASH_SUBSHELL is modified, which is not actually the case.


reply via email to

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