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: Dennis Williamson
Subject: Re: Valid characters for function names
Date: Tue, 26 Nov 2019 10:31:40 -0600

On Tue, Nov 26, 2019, 10:15 AM Chet Ramey <address@hidden> wrote:

> On 11/25/19 5:19 PM, Reuti wrote:
> > Thx for all the replies and links.
> >
> > Nevertheless I wonder about the central place to read about the
> differences between being POSIX compliant or allowing extensions for this
> particular issue. As I noted in my original email from `man bash`:
> >
> > a)
> >        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.
> >
> > b)
> >        name () compound-command [redirection]
> >        function name [()] compound-command [redirection]
> >
> > There is no hint that Bash extends the valid character set to a broader
> range. There is only a note about POSIX mode limiting the to be used names
> not to be one of POSIX special builtins.
>
> "13. Function names must be valid shell 'name's.  That is, they may not
>       contain characters other than letters, digits, and underscores, and
>       may not start with a digit.  Declaring a function with an invalid
>       name causes a fatal syntax error in non-interactive shells."
>
> That's from the section on POSIX mode in the texinfo manual. There's a
> reference to it as a separate link in the man page.
>
>
>   In b) maybe "fname" should be used with a proper definition of "fname"
> beforehand. Then it could be phrased: 'In POSIX mode "fname" is limited to
> represent a "name".'
>
> 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.
>
> --
> ``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/
>


$ foo/bar () { echo "Oh, yeah?"; }
$ foo/bar
Oh, yeah?
$
GNU bash, version 5.0.3(1)-release (x86_64-apple-darwin18.2.0)

>


reply via email to

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