1

I have the following variables

my_country_code="green"
x="country"

echo ${my_$x_code}
bash: ${my_$x_code}: bad substitution

echo should print green as output, but unable to find any technique which will give the correct output

k_vishwanath
  • 1,056
  • 1
  • 15
  • 25

1 Answers1

3
my_x_code="my_${x}_code"
echo ${!my_x_code}
Chris Dodd
  • 111,130
  • 12
  • 123
  • 212
  • Do keep in mind the note re: questions which "...have already been asked and answered many times before" in the "Answer Well-Asked Questions" section of [How to Answer](https://stackoverflow.com/help/how-to-answer) – Charles Duffy Sep 27 '18 at 03:26