Sorry, that was all too confusing, (my bad)
Let me try to explain again, but with a more simple example:
#define a new var and export it to the "env":
export VAR_ONE=thisIsVarOne
# check if it was created:
env | grep VAR_ONE #this displays: "VAR_ONE=thisIsVarOne"
# use it in a simple echo command:
echo VAR_ONE=$VAR_ONE #this displays: "VAR_ONE=thisIsVarOne"
create a new var with the name that contains the value of VAR_ONE ("newvarthisIsVarOne") in its name:
export newvar${VAR_ONE}="somePrefix${VAR_ONE}"
verify if it has been created:
env | grep newvar # this displays: "newvarthisIsVarOne=somePrefixthisIsVarOne"
Now my question:
How do I use that new, syntetic, variable?
Please note that:
env | grep newvar
shows that there has been created a variable with the name newvar${VAR_ONE}
But I can't address that new variable, e.g. in an echo command. I tried:
echo ${newvar${VAR_ONE}}
But that gave me bash: ${newvar${VAR_ONE}}: bad substitution
Constraints:
- The value of VAR_ONE can change, so I can't use that to address the newly created variable
- I can't declare a new variable with a static name. For usage, further in the script, I need the keyword
VAR_ONE
as part of the name of the newly created variable. The name of the variable needs to be something like:newvar${VAR_ONE}
Thank you in advance ChriV
set -x
(set +x
to turn off) and you'll see lines begingging with+
where all shell pre-processing is complete, so you'll see how the shell interpretsecho newvar${VAR}=${newvar${VAR}}
, for example and then the output from executing that command (the normal output). – shellter Nov 17 '23 at 18:24