Operating System - HP-UX
1834578 Members
3416 Online
110069 Solutions
New Discussion

Re: intrepretation variable of variable

 
SOLVED
Go to solution
Vlad_11
Frequent Advisor

intrepretation variable of variable

This is what I have :

CURRENT="abc"
SYSTEM=â abcâ
â ¦..
if [ $SYSTEM = "$CURRENT" ]; then #abc=abc
break
fi
....


And this is what I need to to, i.e. substitute $CURRENT in evaluation with $TARGET

$TARGET='$CURRENT'
CURRENT="abc"

if [ $SYSTEM = "$TARGET" ]; then #abc=$CURRENT
break
fi
....

So far I canâ t make $TARGET being interpreted into â abcâ , played enough with all â â / ` but nothing works, Is i
beer or not beer
6 REPLIES 6
Michael Schulte zur Sur
Honored Contributor
Solution

Re: intrepretation variable of variable

Hi,

if I understand you correctly you look for something like:

TARGET=`echo $CURRENT`
CURRENT="abc"
echo $TARGET

greetings,

Michael

Vlad_11
Frequent Advisor

Re: intrepretation variable of variable

Sorry, Michael
Hope now made it more clear:
Assume code:

TARGET=â $CURRENTâ
CURRENT="abc"
SYSTEM=â abcâ

if [ $SYSTEM = "$TARGET" ]; then
echo â It workssssssssssssssss!!!!â

fi

I need assign value to TARGET thru value of CURRENT=abc, and then produce evaluation like:
If [ abc = abc];
Please assume all special characters (quotes) as just my bad trying, it doesnâ t work so far. But $TARGET should be i
beer or not beer
Vlad_11
Frequent Advisor

Re: intrepretation variable of variable

Hope it will looks OK now:
Assume code :

TARGET='$CURRENT'
CURRENT="abc"
SYSTEM="abc"

if [ $SYSTEM = "$TARGET" ]; then
echo "It workssssssssssssssss!!!!"

fi

beer or not beer
James A. Donovan
Honored Contributor

Re: intrepretation variable of variable

If I understand you correctly, what you're trying to do is not possible in shell programming. There is no concept of a pointer in shell programming. Once you set the value of TARGET, changing the value of current will not dynamically change the value of TARGET.
Remember, wherever you go, there you are...
Sathish C
Frequent Advisor

Re: intrepretation variable of variable

Hi
even though I couldn't get you clearly , have a look at this ,

var1=abc
abc2=hpux

if you wanna print the valut hpux through var1 then your command will be

eval echo "\${var1}2}" will give you the result hpux .

Sathish C
Some cause happiness wherever they go; others, whenever they go
Elmar P. Kolkman
Honored Contributor

Re: intrepretation variable of variable

I think you can solve it like this:
if [ "$SYSTEM" = $(eval echo $TARGET) ]
then
echo "It WORKSSSSSSSS"
else
echo "Sorry, my pressssiousssssss"
fi

;-)
Every problem has at least one solution. Only some solutions are harder to find.