Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: "return" behaves differently in .zlogout (Was: Subshell return codes are discarded during logout?)



On Thu, Dec 26, 2024 at 4:44 PM Lawrence Velázquez <larryv@xxxxxxx> wrote:

That said, misplaced "return" really does behave differently on
logout than it does otherwise.

        outer% cat /tmp/workers-53281/.zlogout
        print reached
        return 42
        print notreached
        outer% ZDOTDIR=/tmp/workers-53281 PS1='inner%% ' zsh -l
        inner% exit
        reached
        outer% print $?
        0

Is this intentional?  Seems like a needless discrepancy.

It's intentional and you can see why if you do this:

outer% ZDOTDIR=/tmp/workers-53281 PS1='inner%% ' zsh -l
inner% exit 14
reached
outer% print $?
14

That is, "return" does not clobber the exit status specified for the top-level shell, whereas a subsequent explicit "exit" does so.



Messages sorted by: Reverse Date, Date, Thread, Author