Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Do local functions exist in Zsh?
- X-seq: zsh-workers 53609
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: Joachim Ansorg <mail@xxxxxxxxxxxxxxx>, zsh-workers@xxxxxxx
- Subject: Re: Do local functions exist in Zsh?
- Date: Tue, 13 May 2025 16:00:08 +0100 (BST)
- Archived-at: <https://zsh.org/workers/53609>
- Feedback-id: 20250513-p.w.stephenson@xxxxxxxxxxxx:oxsmtp-prd-nl-vmo:Authrelay:p.w.stephenson@xxxxxxxxxxxx
- Importance: Normal
- In-reply-to: <b23a5c7c-f8e9-473e-9a9b-03ab9719fc73@bashsupport.com>
- List-id: <zsh-workers.zsh.org>
- References: <b23a5c7c-f8e9-473e-9a9b-03ab9719fc73@bashsupport.com>
> 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
somewhat hidden as local without quotation is interpreted early by the
shell to allow special handling of array assignments, so you wouldn't
usually see that effect, but you can see it for example with
% local foo() { print This is not the local you want.; }
% 'local'
This is not the local you want.
That syntax is only really useful for special functions, in particular
traps, and if you find it confusing you can turn it off.
setopt nomultifuncdef
cheers
pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author