2

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,326
  • 2
  • 20
  • 28

1 Answers1

4
my_x_code="my_${x}_code"
echo ${!my_x_code}
Chris Dodd
  • 119,907
  • 13
  • 134
  • 226
  • 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