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