[Top][All Lists]

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

Re: Document what's allowed in function names

From: Stephane CHAZELAS
Subject: Re: Document what's allowed in function names
Date: Tue, 24 May 2011 20:00:49 -0000
User-agent: slrn/pre1.0.0-18 (Linux)

2011-04-11, 09:51(-04), Chet Ramey:
>> Machine Type: i686-pc-linux-gnu
>> Bash Version: 4.2
>> Patch Level: 8
>> Release Status: release
>> Description:
>>      man bash is currently lacking information on what is allowed for 
>> function
>>      names. It implies name with name () compound-command [redirection] and
>>      at the start of the manual there is:
>>      name   A word consisting only of alphanumeric characters and 
>> underscores,
>>      and beginning with an alphabetic character or an underscore.  Also 
>> referred
>>      to as an identifier.
>>      In reality the rules for function names are much more loose. For example
>>      hyphen and forward slash are allowed. But there are still some 
>> restrictions:
>>      bash: `aa\'foo': not a valid identifier
> It was a mistake to allow such characters in function names (`unset' doesn't
> work to unset them without forcing -f, for instance).  We're stuck with them
> for backwards compatibility, but I don't have to encourage their use.

Why would you put any restriction on the allowed name of a function?

At calling time, it's the same namespace as an argv[0] so any
arg so could be any string.

In zsh, any string is allowed including the empty string (and
allowing the NUL character as that is allowed in arguments to
functions or built-in commands).

$ ''()echo foo
$ ""
$ /bin/ls() echo bar
$ /bin/ls


reply via email to

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