Reputation: 3516
Example:
X=TEST
TEST_VAR=123
eval echo ${${X}_VAR}
This gives the error:
${${X}_VAR}: bad substitution
How can I achieve what I'm looking to do?
Upvotes: 3
Views: 294
Reputation: 84589
Or avoid eval
altogether with a nameref
(created with declare -n
), e.g.
#!/bin/bash
X=TEST
TEST_VAR=123
declare -n foo=${X}_VAR
echo $foo
Example Use/Output
$ ./myscript
123
Upvotes: 2