zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Tycho Kirchner <tychokirchner@mail.de>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: exit_function - strange behavior
Date: Mon, 25 Oct 2021 17:53:13 -0700	[thread overview]
Message-ID: <CAH+w=7bH0sSRzgTOtucm27xGxuUYGNz_U+3S_OFHipm8cR8ZfQ@mail.gmail.com> (raw)
In-Reply-To: <8ce6fada-c1da-c64f-9eb2-ccce5250474a@mail.de>

On Mon, Oct 25, 2021 at 4:28 PM Tycho Kirchner <tychokirchner@mail.de> wrote:
>
> In the function doc for zshexit it states:
>  > Executed at the point where the main shell is about to exit normally.
> This is not called by exiting subshells...

Documentation mistake.  An explicit call to "exit" always triggers the
hook, the reference to "not called by exiting subshells" refers to the
subshell ending by finishing all its commands.

You can avoid that by having the subshell end with "return 123"
instead of "exit 123", except for some reason (possibly a bug) when
the -c option is used in which case return behaves like exit again.

> On the other hand the exit function seems to be not called for the main
> shell, when a subshell called 'exit' immediately before:

That's tricky ... it's because zsh optimizes away one level of shell
when there's nothing else to do after the subshell exits, so the
subshell "becomes" the main shell.

There's definitely a bug in this somewhere because if the last command
executed by the final subshell an anonymous function call:

zsh -fc '...; ( () { return 123 } )'

then the zshexit hook is NEVER called.


  reply	other threads:[~2021-10-26  0:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-25 23:28 Tycho Kirchner
2021-10-26  0:53 ` Bart Schaefer [this message]
2021-10-31 23:52   ` Bart Schaefer
2021-11-01  9:47     ` Tycho Kirchner

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='CAH+w=7bH0sSRzgTOtucm27xGxuUYGNz_U+3S_OFHipm8cR8ZfQ@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=tychokirchner@mail.de \
    --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).