Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

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
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 :-(
Highlighted
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