Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
"return" behaves differently in .zlogout (Was: Subshell return codes are discarded during logout?)
- X-seq: zsh-workers 53287
- From: Lawrence Velázquez <larryv@xxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: "return" behaves differently in .zlogout (Was: Subshell return codes are discarded during logout?)
- Date: Thu, 26 Dec 2024 19:44:09 -0500
- Archived-at: <https://zsh.org/workers/53287>
- Feedback-id: iaa214773:Fastmail
- In-reply-to: <c862a3f3-a256-466c-ab1c-6165c86b60de@app.fastmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <e8ce63b4-2197-46c6-af89-7b73c4c1a113@sev.monster> <c862a3f3-a256-466c-ab1c-6165c86b60de@app.fastmail.com>
On Thu, Dec 26, 2024, at 3:39 PM, Lawrence Velázquez wrote:
> On Thu, Dec 26, 2024, at 12:37 PM, sev wrote:
>> It seems that the return/error codes of subshells are ignored while the
>> shell is shutting down. This happens whether the exit builtin is used
>> or the shell is exiting due to a signal. This can't be intentional? I
>> saw no mention of such an edge-case in the documentation.
>>
>> For example:
>>
>> % cat .zlogout
>> (echo ran; return 1)
>> echo $?
>> % source .zlogout
>> ran
>> 1
>> % exit
>> ran
>> 0
>
> The behavior of "return" is only documented within functions and
> scripts run using "." or "source", so you should avoid using it
> outside those contexts. Your example works fine if you use "exit"
> instead.
That said, misplaced "return" really does behave differently on
logout than it does otherwise.
outer% cat /tmp/workers-53281/.zshrc
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
outer% zsh /tmp/workers-53281/.zlogout
reached
outer% print $?
42
Is this intentional? Seems like a needless discrepancy.
--
vq
Messages sorted by:
Reverse Date,
Date,
Thread,
Author