On 8/14/21 8:45 PM, Hunter Wittenborn wrote:
> Hi,
> 
> 
> 
> I was doing some testing for some additions to a rather big Bash script I'm 
> working on, and the following code kept failing whenever I attempted to run 
> it:
> 
> 
> 
> "
> 
> variable="hello"
> 
> 
> 
> declare -g "${variable}"=("world" "me")

Here's the answer I gave on help-bash:

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    c...@case.edu    http://tiswww.cwru.edu/~chet/

Reply via email to