Re: Characters in function names

On Feb 11, 1:53 pm, Stephane Chazelas <stephane_chaze...@xxxxxxxx>
On Mon, 11 Feb 2008 03:04:32 -0800 (PST), Spiros Bousbouras wrote:
Which characters can appear in function names
in BASH ? Other shells ?

As they share the same namespace as command arguments, intuition
would say any character but the NUL character, but YMMV.

But command arguments don't have a namespace meaning that
the shell doesn't store them anywhere. Or do you mean command
names ? If you mean command (as in executable) names then
it's not completely the same with function names because
with functions the shell has to be able to also parse the
definition correctly. But since you're saying that zsh allows
anything I guess it is possible.

zsh allows everything. Even the empty string or the NUL
character (zsh is the only shell to allow NUL bytes where
applicable) are valid function names.

I wonder how one defines or calls a function whose
name only contains NUL bytes.

Other shells may have restrictions, but they would be artificial
as there's no reason at all to put a restriction here.

An argument could be made for not allowing = in a function name
because if you type something like t=5 it's not clear if you mean
an assignment or you want to execute a function called t=5. The
same ambiguity can arise with executable names but executable names
are up to the filesystem and a shell has no control over that.