assignment to variable from eval command

Hi Gurus,

I am having 2 parameters as below

parm1=value1
parm2=parm1

I want to evaluate parm1 value using eval echo \$$parm2 and later i want to assign this value to other variable which i will be using in if statement like :

if [[ $var=='value1 ]]; then
do this.......
fi

could you please suggest some way as I am not able to achieve this.

Try...

eval var=\$$parm2

Thanks a lot

It worked for me !!

---------- Post updated at 03:07 PM ---------- Previous update was at 02:52 PM ----------

One more thing Ygor,

Its working when I am executing from command line, but same is not working when I am putting it in to a script :

for prm in RUN_COST_PRICES_COMPARISON RUN_SELLING_PRICE_COMPARISON RUN_RATIO_PACK_COMPARISON
>     do
>     echo $prm
>     eval VAR=\$$prm
>     echo $VAR
> done
RUN_COST_PRICES_COMPARISON
Y
RUN_SELLING_PRICE_COMPARISON
N
RUN_RATIO_PACK_COMPARISON
Y

But when the same thing kept in the script eval command is not working.

./aa
RUN_COST_PRICES_COMPARISON

RUN_SELLING_PRICE_COMPARISON

RUN_RATIO_PACK_COMPARISON

Could you pleases advice if something needs to be added

---------- Post updated at 03:33 PM ---------- Previous update was at 03:07 PM ----------

Can someone please help me on this. Thanks

for prm in RUN_COST_PRICES_COMPARISON RUN_SELLING_PRICE_COMPARISON RUN_RATIO_PACK_COMPARISON
do
echo $prm
echo ${!prm}
done

Are the variables filled in your script?
to verify, add this to the the previous one:

echo "before expansion"
echo $RUN_COST_PRICES_COMPARISON
echo $RUN_SELLING_PRICE_COMPARISON
echo $RUN_RATIO_PACK_COMPARISON
echo "------------------"

Hi,

I am using ksh version, so this is failing with below error :

./aa[8]: ${!prm}: 0403-011 The specified substitution is not valid for this command.

It works fine for me with the same script you use..

RUN_COST="Y"
RUN_SELLING="N"
RUN_RATIO="Z"

for prm in RUN_COST RUN_SELLING RUN_RATIO
do
     echo $prm
     eval VAR=\$$prm
     echo  "$VAR"
done

Ouyput:
RUN_COST
Y
RUN_SELLING
N
RUN_RATIO
Z

Are the RUN_COST*..etc have values assigned in the script? Or try as echo "$VAR"