1

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

terdon
  • 242,166
Michael
  • 11

1 Answers1

3

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.