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

Re: Subshell return codes are discarded during logout?



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