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

Re: Do local functions exist in Zsh?



On Tue, May 13, 2025, at 11:00 AM, Peter Stephenson wrote:
>> On 13/05/2025 15:51 BST Joachim Ansorg <mail@xxxxxxxxxxxxxxx> wrote:
>> I'm maintaining basic Zsh support in BashSupport Pro, a JetBrains IDE 
>> plugin.
>> 
>> A user requested support for "local functions" at 
>> https://github.com/BashSupport-Pro/bashsupport-pro/issues/200
>> 
>> In my tests, Zsh 5.9 accepts "local foo() { : }" as valid syntax.
>> Is this syntax intentional?
>
> No, I'm afraid that's not doing what you want. It's defining both
> local and foo as equivalent names for the same function.

This is documented, but it's admittedly easy to overlook, especially
if you're not reading closely.

	function [ -T ] WORD ... [ () ] [ TERM ] { LIST }
	WORD ... () [ TERM ] { LIST }
	WORD ... () [ TERM ] COMMAND

		where TERM is one or more newline or ';'.  Define
		a function which is referenced by any one of WORD.
		Normally, only one WORD is provided; multiple WORDs
		are usually only useful for setting traps.

https://zsh.sourceforge.io/Doc/Release/Shell-Grammar.html#index-function

-- 
vq




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