[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Valid characters for function names
From: |
Stephane Chazelas |
Subject: |
Re: Valid characters for function names |
Date: |
Tue, 26 Nov 2019 17:31:02 +0000 |
User-agent: |
NeoMutt/20180716 |
2019-11-26 11:14:38 -0500, Chet Ramey:
[...]
> This is a reasonable addition, with the caveat that `fname' is virtually
> unlimited. It can't contain any quoted characters, or contain NUL (like any
> bash string) or `$' (and that is dubious). You can even define a function
> whose name contains a slash -- you'll just never be able to call it.
[...]
It can't contain delimiter characters like space, tab, newline
(possibly other blanks in single-byte locales), |, &, ;, <, >,
(, ) either.
I don't think you can create a function whose first character is
#.
You can't use = either if what's left of the first occurrence is
a valid variable name (or a valid variable name followed by +).
It seems you can't have a function name that is made of only
decimal digits. (Defining it as -123 or +123 is OK though).
You can't have a function with a an empty name.
zsh allows any name, and performs expansions and quote removal
on the function name. So you can have a function with an empty
name:
''() { echo empty; }
Or NUL:
$'\0' { echo nul; }
Or by any filename that matches a wildcard:
/etc/* { echo x; }
It makes sense to not put any more limit to that argv[0]
argument than to any other argument.
The "rc", "es", "fish" shells also have very few restrictions on
function names. "rc" also has few restrictions on variable
names.
The constraints in current shells are generally accidents of
implementation. The Bourne shell used the same namespace for
variables and functions (you could not define a function and
variable by the same name).
--
Stephane