Operating System - Linux
1753782 Members
7277 Online
108799 Solutions
New Discussion юеВ

Re: how to evaluate this variable

 
SOLVED
Go to solution
Gemini_2
Regular Advisor

how to evaluate this variable

say if I have

fred=/tmp
fred2=fred

how do I get the variable for fred from fred2

if I do echo "$fred2", it doesnt work..

I tried many ways, none of that work, please advise...


5 REPLIES 5
Gemini_2
Regular Advisor

Re: how to evaluate this variable

posted too fast...I meant to say. I want to get the value of fred from fred2...

like "echo $fred2" will print "/tmp"

I know "echo $fred2" is wrong..."echo $$fred2" is also wrong :-(
John Poff
Honored Contributor
Solution

Re: how to evaluate this variable

Try using 'eval'. Here is one way to do it:

eval echo \$$FRED2
/tmp


JP
Keith Johnson
Valued Contributor

Re: how to evaluate this variable

If you want to set fred2 to the value of fred, try this...

fred=/tmp
fred2=$fred

KJ
No matter where you go...there you are.
John Poff
Honored Contributor

Re: how to evaluate this variable

Oops. I used upper case and you used lower:

eval echo \$$fred2
/tmp

Gemini_2
Regular Advisor

Re: how to evaluate this variable

such easy answer..I was so close..

I used

`eval echo \$$i`

I should not put ` `, it will make it evalute 3 times :-(

thank you!!

I got it