help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Valid characters for function names


From: Chet Ramey
Subject: Re: Valid characters for function names
Date: Tue, 26 Nov 2019 13:55:07 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.2.2

On 11/26/19 12:31 PM, Stephane Chazelas wrote:
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.

Because trying it would require you to quote the character.

I don't think you can create a function whose first character is
#.

Same.


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 +).

Same, unless you use `function':

$ function foo=bar
> {
> echo a
> }
$ \foo=bar
a



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

$ 1()
> {
> echo a
> }
$ 1
a

Current devel branch.


You can't have a function with a an empty name.

That contains a NUL, but I get your point.


zsh allows any name, and performs expansions and quote removal
on the function name. So you can have a function with an empty
name:

Not exactly relevant here.

Bottom line is basically that you need a WORD and anything that the
parser treats as higher precendence than a WORD requires quoting, which
disqualifies it as a function name. You can't have a reserved word
without using `function', either, for instance.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://tiswww.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]