Assign values to variable

Hi Masters,

I want to assign the values of one variable to another variable.

Here the varaible name 'var' is dynamic. I know the values of V_2 and U_3, but
If the i/p of TYPE is 'U' and the NO is 3, then I want to assign the values of
U_3 to var.

How we can achieve it?

TYPE="U"
NO="3"

V_2="3 2 4"; export V_2
U_3="1 2 3" ; export U_3

var=${TYPE}_${NO}

If I say echo $var, then it should print 1 2 3

Thanks for your time.

don't say

echo $var

but just try

eval echo \$$var

or

eval echo \$${TYPE}_${NO}

Thank you ctsgnb.

Its printing correctly.

But how I can assign the values to my variable 'var'

just don't use it.

when you need the 'dynamic value' of var so... when you need $var,
just refer to it as

$(eval echo \$${TYPE}_${NO})

Indeed if you do

var=${TYPE}_${NO}

then, if TYPE and NO are changed after that assignation to var, var will not be changed until you do this var assignation again :

var=${TYPE}_${NO}

---------- Post updated at 05:49 PM ---------- Previous update was at 05:43 PM ----------

Enter this succession of command and see the result

TYPE="U"
NO="3"
V_2="3 2 4"
U_3="1 2 3"
var=${TYPE}_${NO}
eval echo \$$var
eval echo \$${TYPE}_${NO}
TYPE="V"
NO="2"
eval echo \$$var
eval echo \$${TYPE}_${NO}

The statement in red will give you the old value of $var this is because var has not been reassigned (with var=${TYPE}_${NO} ) since TYPE and NO have changed to V 2...

Thanks Once again Man.

Its working as expected.