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

1
  • x=country; declare "my_${x}_code=green"; var="my_${x}_code"; echo "${!var}" Commented Sep 27, 2018 at 3:07

1 Answer 1

4
my_x_code="my_${x}_code"
echo ${!my_x_code}
Sign up to request clarification or add additional context in comments.

1 Comment

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.