What am I doing wrong here?
A_B_NAME="something"
X=A
Y=B
RESULT=`echo \${X}_\${Y}_NAME`
echo ${RESULT}
and I'm always getting A_B_NAME as a result, but want "something"
Thanks!
Michael
What am I doing wrong here?
A_B_NAME="something"
X=A
Y=B
RESULT=`echo \${X}_\${Y}_NAME`
echo ${RESULT}
and I'm always getting A_B_NAME as a result, but want "something"
Thanks!
Michael
You could use eval
here (standard):
eval "RESULT=\$${X}_${Y}_NAME"
Or the bash
-specific:
varname=${X}_${Y}_NAME
RESULT=${!varname}
And then:
printf '%s\n' "$RESULT"
remember echo
can't be used to output arbitrary data, and parameter expansions must be quoted when in list contexts.
\${X}_\${Y}_NAME
is not the variableA_B_NAME
, which is$A_B_NAME
. – schrodingerscatcuriosity Feb 19 '20 at 20:13