[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Valid characters for function names
From: |
Reuti |
Subject: |
Valid characters for function names |
Date: |
Mon, 25 Nov 2019 15:41:30 +0100 |
User-agent: |
Horde Application Framework 5 |
Hi,
I got a script using foo++() as function name, and at first I was
confused of a different behavior between bash 4.2, 4.4 and 5.0. After
crawling some mailing lists whether this is allowed at all, I found
this post:
first)
https://lists.gnu.org/archive/html/help-bash/2018-12/msg00067.html
Obviously the behavior regarding such a constructed name in 4.2 and
4.4 was not always coherent. And a plus sign is one of the additional
characters which Bash allows as an extension.
Nevertheless, also the version 5.0 has in its man-page the passage:
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]
Shouldn't this be extended in the man-page to list all valid
characters? I even wonder where the original poster got the list from.
===
second)
bash-5.0$ foo() { echo Yes; }
bash-5.0$ foo
Yes
bash-5.0$ unset foo
bash-5.0$ foo
bash: foo: command not found
bash-5.0$ baz++() { echo Yes; }
bash-5.0$ baz++
Yes
bash-5.0$ unset baz++
bash: unset: `baz++': not a valid identifier
bash-5.0$ unset -f baz++
Hence there is a rule: if special characters are used inside a
function name, the the option -f must be used.
Maybe this is related to the fact, that `unset` works for both:
variables and (and afterwards) for left functions with this name.
Would it be sensible to jump inside `unset` to scan for a function
name, once an illegal name for a variable was found? – Or make the use
of "-f" always mandatory for functions?
-- Reuti
- Valid characters for function names,
Reuti <=