help-bash
[Top][All Lists]
Advanced

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

Re: So confused: bash vs ssh and SHLVL=0?


From: Chet Ramey
Subject: Re: So confused: bash vs ssh and SHLVL=0?
Date: Mon, 12 Oct 2020 10:13:08 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.3.1

On 10/11/20 4:08 PM, Paul Smith wrote:
> On Sun, 2020-10-11 at 15:05 -0400, Chet Ramey wrote:
>> Here's part of the discussion of the issue:
>>
>> https://lists.gnu.org/archive/html/bug-bash/2016-09/msg00000.html
> 
> Thanks, that's interesting (although it's not clear, were changes made
> as a result of that email?)

Yes, I made changes as a result of that report.

> 
>>> Can anyone explain how or why bash decides to decrement SHLVL when
>>> invoking a process?
>>
>> Basically, it decrements the shell level before performing the
>> equivalent of the `exec' builtin. Sometimes it optimizes out a fork
>> to make it equivalent to an exec. Ordinarily it doesn't matter.
> 
> Thanks for pointing me at the pipeline, I didn't even think about that
> as part of the prerequisites.  Leaving aside the sourcing of bashrc,
> though, the handling of SHLVL just seems weird: in bash 5.0.17:
> 
>   $ echo $SHLVL
>   1
> 
>   $ echo 'all: ; @echo $(SHLVL) $$SHLVL' > /tmp/x.mk
> 
>   $ make -f /tmp/x.mk SHELL=/bin/bash
>   1 2
> 
>   $ make -f /tmp/x.mk SHELL=/bin/bash | cat
>   0 1
> 
> ???

This is exactly the situation I described. Bash decrements shell_level
before executing make, make, I assume, expands its own value of SHLVL
before invoking the shell to execute the command, the shell increments
SHLVL at startup and expands it.

I think I can figure out a way to exempt pipelines from this behavior.
I'll look at that after bash-5.1 is released.


>> I'd file a bug report with Debian.
> 
> I can do that.  But, given how long it's been set it seems like getting
> them to un-set it would be a very big ask.  Probably of the "not gonna
> happen" variety.

I suppose they think the non-default behavior is better for more of their
users.


-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/



reply via email to

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