Andreas Wong
Andreas Wong

Reputation: 60516

bash expanding value of a variable to use in another variable

I hope the question makes sense, I would like to do something like:

a=test
b=a
echo ${$b} # should echo test

Basically I'd like $b to expand to the value a and have bash echo out the value of variable $a (since ${a} is test).

What syntax should I use?

Upvotes: 2

Views: 129

Answers (1)

bobah
bobah

Reputation: 18864

a=test
b=a
echo ${!b} # does echo test

Upvotes: 3

Related Questions