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: Paul Smith
Subject: Re: So confused: bash vs ssh and SHLVL=0?
Date: Sun, 11 Oct 2020 16:08:37 -0400
User-agent: Evolution 3.36.4-0ubuntu1

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?)

> > 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

???

Using bash 4.4.20, I get the behavior I'd expect in both cases:

  $ make -f /tmp/x.mk SHELL=/bin/bash
  1 2

  $ make -f /tmp/x.mk SHELL=/bin/bash | cat
  1 2

This seems to be the instigation for the change in behavior in Ubuntu
20.04; the SSH_SOURCE_BASHRC option was also enabled in Ubuntu 18.04
(and so has probably been enabled there for a long time) but it didn't
impact me because in 18.04 the SHLVL was not reduced, even when used in
a pipeline.

> > This is clearly not good for my build environment
> > as it causes all my make recipes to have ~/.bashrc sourced, which
> > resets critical environment variables etc.
> 
> 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.

To clarify, do you think the above changed behavior of SHLVL in bash
5.0 is correct?  Where SHLVL is reduced before invoking any random
command IFF it's part of a pipeline?

That doesn't seem like it can be correct, to me, even after reading the
email message you linked.




reply via email to

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