zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Daniel Shahaf <d.s@daniel.shahaf.name>
Cc: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: Re: { exit } always { foo }
Date: Tue, 17 Dec 2019 20:54:44 -0800	[thread overview]
Message-ID: <CAH+w=7bp8JqvMMO=VBGWfag3LgcRtSohWzbwPHWdGKxcfwyqsA@mail.gmail.com> (raw)
In-Reply-To: <b54ed361-ce23-46d5-b5e3-71adcfb5bd6b@www.fastmail.com>

On Tue, Dec 17, 2019 at 7:57 PM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
>
> Which is correct, the manual or the test?

I think both are, although the wording in the doc might be clearer.
This is the important bit (my capitals):

>     An tt(exit) command (or a tt(return) command executed AT THE OUTERMOST
>     function LEVEL of a script) encountered in tt(try-list) does em(not) cause
>     the execution of var(always-list).  Instead, the shell exits immediately
>     after any tt(EXIT) trap has been executed.

The word "function" there is unfortunate because it doesn't mean a
shell function.

In this line:
>   725     mytest() { { exit 3 } always { mywrap }; print Exited before this }

The always block is NOT at the outermost level, so the shell does not
exit immediately.  "Outermost" means that there IS NO surrounding
function scope.  Thus in the following case:

 (
  mywrap() { echo BEGIN; true; echo END }
  { exit 3 } always { mywrap }; print Exited before this
 )

The always block is not executed and mywrap isn't called.  As soon as
you put the "always" inside the "mytest" scope, that rule no longer
applies.

  reply	other threads:[~2019-12-18  4:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-18  3:56 Daniel Shahaf
2019-12-18  4:54 ` Bart Schaefer [this message]
2019-12-18  4:59   ` Bart Schaefer
2019-12-18  5:23   ` Daniel Shahaf
2019-12-19 15:28     ` Daniel Shahaf
2019-12-19 15:37       ` Peter Stephenson
2019-12-19 16:05         ` Daniel Shahaf

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=7bp8JqvMMO=VBGWfag3LgcRtSohWzbwPHWdGKxcfwyqsA@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=d.s@daniel.shahaf.name \
    --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).