zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [PATCHv2] [bug] $SHLVL decremented for the last command of a subshell
Date: Wed, 31 Aug 2016 10:02:30 +0100	[thread overview]
Message-ID: <20160831100230.0892bae1@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <CAHYJk3TaOgdL0zRxcT21ybiLucMoF21vpGJ8QTKKp4eyRah42w@mail.gmail.com>

On Tue, 30 Aug 2016 20:34:34 +0200
Mikael Magnusson <mikachu@gmail.com> wrote:
> > When this was introduced in zsh, there was some controversy over whether
> > it was the right thing to do.  I decided it was on the basis that the
> > "level" is how deep you are in the process hierarchy, rather than how
> > many processes have previously been executed to get where you are,
> > seeing as the latter isn't really visible in the current context.
> > But I'm not aware of any requirement specification [remember those?]
> > saying what the purpose of SHLVL is.
> 
> For me personally, I just use it in my prompt to indicate whether
> typing "exit" will close the terminal or not, eg if I'm inside a
> nested actual shell. When I added that I wasn't even aware of any of
> the weird rules regarding subshells affecting it. It's not immediately
> obvious to me when that is useful...

There are no weird *rules* regarding subshells and SHLVL; the rule is
SHLVL should indicate how deeply nested the parent shell is in process
terms.  The effect with subshells was a bug because we do a fake
exec (i.e. we don't bother forking for the new last command) with the
last process in a subshell because we know the current process
will come to an end anyway.

The decrement is needed in general on a real exec because you are
creating a new shell which isn't more deeply nested, i.e. if you do
"exec zsh" from the command line you (probably) expect SHLVL to look the
same since the nesting level hasn't changed. If everything is working
this is the sole effect (but process management is complicated enough
real life isn't necessarily that simple).

The final question was whether after the fix there was any remaining
business to do with the combination of execs and subshells, but it
doesn't look like there is anything significant.

pws


  reply	other threads:[~2016-08-31  9:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-22  6:17 Stephane Chazelas
2016-08-29 15:51 ` [PATCH] " Stephane Chazelas
2016-08-30  1:55   ` Bart Schaefer
2016-08-30 12:44     ` [PATCHv2] " Stephane Chazelas
2016-08-30 13:04       ` Peter Stephenson
2016-08-30 16:46         ` Stephane Chazelas
2016-08-30 17:00           ` Peter Stephenson
2016-08-30 18:34             ` Mikael Magnusson
2016-08-31  9:02               ` Peter Stephenson [this message]
2016-08-30 19:54             ` Stephane Chazelas
2016-08-30 20:10               ` Stephane Chazelas
2016-08-31 10:06       ` Peter Stephenson
2016-09-04  5:32         ` Stephane Chazelas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160831100230.0892bae1@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).