[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Issue declaring an array via a variable name

From: Hunter Wittenborn
Subject: Issue declaring an array via a variable name
Date: Sat, 14 Aug 2021 19:45:21 -0500
User-agent: Zoho Mail


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:



declare -g "${variable}"=("world" "me")


When run, it's complaining about a syntax error near "(", appearing to be on 
the 'declare' line right next to where I start typing the array.

In my testing, all of the following would fail:

- declare -g "${variable}"=("world" "me")

- declare -g ${variable}=("world" "me")

- declare -g "hello"=("world" "me")

The only one that did work was the following:

- declare -g hello=("world" "me")

This appeared to be a bug for me, but I wasn't sure if this was somehow a 
feature or not.

Lastly: A workaround for this was found here [1] which uses namerefs, and works 
just fine (and is probably easier for me to look at anyway), but this seemed 
like something that deemed a bug report regardless.

[1]: https://lists.gnu.org/archive/html/help-bash/2021-08/msg00069.html


Hunter Wittenborn



reply via email to

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