Re: how to evaluate this variable (225 Views)
Reply
Regular Advisor
Gemini_2
Posts: 188
Registered: ‎11-05-2001
Message 1 of 6 (225 Views)
Accepted Solution

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...


Regular Advisor
Gemini_2
Posts: 188
Registered: ‎11-05-2001
Message 2 of 6 (225 Views)

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 :-(
Honored Contributor
John Poff
Posts: 2,448
Registered: ‎05-22-2001
Message 3 of 6 (225 Views)

Re: how to evaluate this variable

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

eval echo \$$FRED2
/tmp


JP
Valued Contributor
Keith Johnson
Posts: 98
Registered: ‎12-27-2000
Message 4 of 6 (225 Views)

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.
Honored Contributor
John Poff
Posts: 2,448
Registered: ‎05-22-2001
Message 5 of 6 (225 Views)

Re: how to evaluate this variable

Oops. I used upper case and you used lower:

eval echo \$$fred2
/tmp

Regular Advisor
Gemini_2
Posts: 188
Registered: ‎11-05-2001
Message 6 of 6 (225 Views)

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
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.