[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Issue declaring an array via a variable name
From: |
Chet Ramey |
Subject: |
Re: Issue declaring an array via a variable name |
Date: |
Mon, 16 Aug 2021 09:57:29 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 |
On 8/14/21 5:53 PM, Hunter Wittenborn wrote:
> Hi!
>
>
>
> I wasn't sure if this was a bug (though it seemed quite likely for me), so I
> went ahead and decided to post the issue here before resorting over to the
> bug mailing list.
>
>
>
> Anyway - For some reason, the following code keeps failing whenever I run it:
>
>
>
> "
>
> variable="hello"
>
>
>
> declare -g "${variable}"=("world" "me")
It's a syntax error. There is an unquoted operator (`(') where the grammar
does not allow it.
`declare' does allow compound array assignment statements as arguments, and
the parser accommodates this as long as two conditions hold: the parser can
detect that the first word of a simple command is `declare' and the
argument is a valid assignment statement. In this case, the second fails,
since `"${variable}"' is not a valid shell identifier. That renders the
argument not a valid assignment statement.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/