[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 |
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")
"
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
https://www.hunterwittenborn.com
https://github.com/hwittenborn
- Issue declaring an array via a variable name,
Hunter Wittenborn <=
- Re: Issue declaring an array via a variable name, Hunter Wittenborn, 2021/08/19
- Re: Issue declaring an array via a variable name, Oğuz, 2021/08/20
- Re: Issue declaring an array via a variable name, Hunter Wittenborn, 2021/08/21
- Re: Issue declaring an array via a variable name, Alex fxmbsw7 Ratchev, 2021/08/21
- Re: Issue declaring an array via a variable name, Lawrence Velázquez, 2021/08/21
- Re: Issue declaring an array via a variable name, Oğuz, 2021/08/22
- Re: Issue declaring an array via a variable name, Chet Ramey, 2021/08/22
- Re: Issue declaring an array via a variable name, Alex fxmbsw7 Ratchev, 2021/08/22