Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Subshell return codes are discarded during logout?
- X-seq: zsh-workers 53286
- From: Lawrence Velázquez <larryv@xxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: Subshell return codes are discarded during logout?
- Date: Thu, 26 Dec 2024 15:39:54 -0500
- Archived-at: <https://zsh.org/workers/53286>
- Feedback-id: iaa214773:Fastmail
- In-reply-to: <e8ce63b4-2197-46c6-af89-7b73c4c1a113@sev.monster>
- List-id: <zsh-workers.zsh.org>
- References: <e8ce63b4-2197-46c6-af89-7b73c4c1a113@sev.monster>
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.
outer% cat /tmp/workers-53281/.zshrc
outer% cat /tmp/workers-53281/.zlogout
(echo foo; return 1); echo $?
(echo bar; exit 1); echo $?
outer% ZDOTDIR=/tmp/workers-53281 PS1='inner%% ' zsh -l
inner% exit
foo
0
bar
1
outer%
--
vq
Messages sorted by:
Reverse Date,
Date,
Thread,
Author