Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use Variable to echo another Variable 2

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
DE
Hi folks,

I'm not sure how to explain my problem ...

I'm using a lot of variables. Let's say e.G.

Code:
AA=Hello
BB=How
CC=Where

Next I do something like:

Code:
read input

Where "input" can be "AA", "BB", "CC".

Now the tricky part is:
I'd like to get the content of the variable name I entered into the input variable so that if someone enters "AA" the echo would produce me a "Hello" on screen.

I tried something like this:

Code:
echo \$$input

But this would only give me the following in return:

Code:
$AA

Any ideas ?

Regards,
Thomas
 
Try this...
Code:
eval echo \$$input
The "[tt]eval[/tt]" causes the line to be parsed twice. The backslash protects the first dollar sign to make it to the second parsing.
 
And if you want to store the value before echoing:
eval newvar="\$$input"; echo $newvar

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Perfect, exactly what I need ...

Thanks a lot everyone !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top