What is the trick to propagate the value of a variable?

e.g. Test="ABC" and ABC="xyz"

I am expecting that $Test returns xyz. Any hack to to do this?

I tried $($Test) and ${$Test} but am getting wrong output. Any similar approach I can try with?


I suggest:

echo "${!Test}"



This is known as indirect expansion.

| improve this answer | |
  • Thanks. Just to know is there anything like $($Test)? Since I have to use inside for loop – Rocky86 Jun 21 '17 at 18:27
  • This is not known to me. – Cyrus Jun 21 '17 at 18:44
  • 2
    @Rock, that's starting to sound like you actually need something completely different (possibly arrays). You might want to ask another question about what you're actually trying to do in the end. (I would say to clarify this one, but I'm not sure if it's fair for Cyrus who already answered.) – ilkkachu Jun 21 '17 at 18:47
  • @ilkkachu Cyrus answer is correct. But just for information I was expecting if we can have another alternative to achieve similar – Rocky86 Jun 21 '17 at 18:50
  • @rock: If I think it exactly, then there is still a second solution. But unfortunately, a reflex-like downvote is performed by some users when a specific command is used. – Cyrus Jun 21 '17 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.