Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: { exit } always { foo }
On Tue, Dec 17, 2019 at 7:57 PM Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> 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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author