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.

Relevant Pages

  • Re: Search and replace in one field
    ... where you don't wnat the " replaced by another character. ... the s command is the substitute command. ... However " is meaningful to the shell but preceding a character with a backslash tells the shell to ignore it so where the line contains \" the shell removes the \ and passes the " to the command. ... So what sed sees as its first parameter is s/"//g which tells it to replace all occurrences of " with nothing. ...
  • Re: Excercices
    ... > example or get a better shell. ... program (in cmd.exe it is an internal command), ... In the above example there is neither a escape character nor ... You are called "Phil" so you can be distinguished from other ...
  • Re: Characters in function names
    ... As they share the same namespace as command arguments, ... would say any character but the NUL character, ... the shell doesn't store them anywhere. ...
  • Re: () $() etc., in Bash
    ... It is replaced on the command line by the output of the command ... different from one shell to another) on the character string ... linefeed character has been removed. ...
  • FAQ - Answers to Frequently Asked Questions Part 2.
    ... character except '\0' is allowed in a file path on Unix. ... the default shell" isn't a good reason. ... command line buffer), and will fail if any file names contain a ... How do I use shell variables in awk scripts ...