Combine two variables

March 31, 2011 at 10:10:56
Specs: AIX
Using ksh, can I use one variable to form part of another i.e.

FS1=random
FS2=itworks
MYVAR=2

echo $FS($MYVAR)

... i want this to display "itworks"


See More: Combine two variables

Report •

#1
March 31, 2011 at 10:23:24
FS2=itworks
MYVAR=2

# create a shell variable
eval FS$MYVAR=\$FS2
echo $FS2 # should display: itworks


Report •

#2
March 31, 2011 at 10:30:33
thanks nails... still struggling though i'm afraid (new to ksh etc!)

My value for MYVAR is going to be changing and i'll have a lot of stored variables eg

FS1 = one
FS2 = two
FS3 = three

so i want to be able to substitute MYVAR in place of the number and simply print/echo the result.

Does that makes sense?


Report •

#3
March 31, 2011 at 10:34:25
Sorry, my bad. This should do it:

eval echo \"\$FS$MYVAR\"


Report •
Related Solutions


Ask Question