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?)



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