Steve Amerige
2018-05-14 10:08:46 UTC
I have code that implements an object-oriented array "class" in Bash.
One of the functions is named object:[.
The problem I'm encountering is that doing declare -f 'object:[' emits
an error.
Here is a demonstration of the problem:
object:[()
{
echo 'Function works'
}
% object:[
Function works
%
% declare -f 'object:['
bash: declare: `object:[': not a valid identifier
%
The function can be declared and invoked without any problems. The only
issue is that declare -f object:[ fails. I've tried escaping the
backslash and various quoting, but I have not been able to get declare
-f to work as expected.
I do note that if type just declare -f without a function name, then I
do see in the output the function as declared above.
I have tested with identical failures as shown above in each case using
the following Bash versions:
- GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
- GNU bash, version 4.3.30(1)-release (x86_64-unknown-linux-gnu)
- GNU bash, version 4.4.18(1)-release (x86_64-unknown-linux-gnu)
Is this a bug in Bash? Is there any workaround?
My Bash version is: GNU bash, version 4.2.46(2)-release
(x86_64-redhat-linux-gnu).
I'm on an up-to-date CentOS 7.4 OS.
I'm not invoking Bash in POSIX mode.
Thanks,
Steve Amerige
P.S. I found the following. Are any of them indicative of the same or
related problems?
% cd ~/src/bash-4.4.18/tests
% grep -r 'declare.*not a valid identifier'
array.right:./array2.sub: line 1: declare: `[]=asdf': not a valid
identifier
assoc.right:./assoc5.sub: line 13: declare: `myarray[foo[bar]=bleh':
not a valid identifier
nameref.right:./nameref11.sub: line 4: declare: `/': not a valid
identifier
nameref.right:./nameref11.sub: line 24: declare: `': not a valid
identifier
nameref.right:./nameref12.sub: line 26: declare: `42': not a valid
identifier
nameref.right:./nameref12.sub: line 45: declare: `7*6': not a valid
identifier
errors.right:./errors.tests: line 60: declare: `-z': not a valid
identifier
errors.right:./errors.tests: line 61: declare: `/bin/sh': not a valid
identifier
One of the functions is named object:[.
The problem I'm encountering is that doing declare -f 'object:[' emits
an error.
Here is a demonstration of the problem:
object:[()
{
echo 'Function works'
}
% object:[
Function works
%
% declare -f 'object:['
bash: declare: `object:[': not a valid identifier
%
The function can be declared and invoked without any problems. The only
issue is that declare -f object:[ fails. I've tried escaping the
backslash and various quoting, but I have not been able to get declare
-f to work as expected.
I do note that if type just declare -f without a function name, then I
do see in the output the function as declared above.
I have tested with identical failures as shown above in each case using
the following Bash versions:
- GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
- GNU bash, version 4.3.30(1)-release (x86_64-unknown-linux-gnu)
- GNU bash, version 4.4.18(1)-release (x86_64-unknown-linux-gnu)
Is this a bug in Bash? Is there any workaround?
My Bash version is: GNU bash, version 4.2.46(2)-release
(x86_64-redhat-linux-gnu).
I'm on an up-to-date CentOS 7.4 OS.
I'm not invoking Bash in POSIX mode.
Thanks,
Steve Amerige
P.S. I found the following. Are any of them indicative of the same or
related problems?
% cd ~/src/bash-4.4.18/tests
% grep -r 'declare.*not a valid identifier'
array.right:./array2.sub: line 1: declare: `[]=asdf': not a valid
identifier
assoc.right:./assoc5.sub: line 13: declare: `myarray[foo[bar]=bleh':
not a valid identifier
nameref.right:./nameref11.sub: line 4: declare: `/': not a valid
identifier
nameref.right:./nameref11.sub: line 24: declare: `': not a valid
identifier
nameref.right:./nameref12.sub: line 26: declare: `42': not a valid
identifier
nameref.right:./nameref12.sub: line 45: declare: `7*6': not a valid
identifier
errors.right:./errors.tests: line 60: declare: `-z': not a valid
identifier
errors.right:./errors.tests: line 61: declare: `/bin/sh': not a valid
identifier