Storing Multiple Values in a Variable

Hi,

My code is as below:

integer i=7
while ((i <= 5 ));
do
# test_out is a variable which contains data separated by "^".

a= `echo $test_out | cut -d"^" -f$i`

echo "$a"

(( i = i + 1));
done

From the above code, i kept $i after f so that i can capture all the data which is separated by "^". Here since "i" is incrementing 5 times, i want to store all the 5 values in variables such as a1,a2,a3,a4,a5 .

How can i do this. If i keep "i" after a it is not working. Ideally instead of keeping 5 commands for a, i want to do it in single shot by keeping ai. But it is not working.

If i do an echo "$ai", it must display all the 5 values since its looping 5 times.

Correct me if i mentioned some thing wrong. I am new to UNIX so it would be great if some body can help me out.

Thanks
Sandeep

Assuming you are using the Korn shell, the following example should show you how to do what you want

integer i=1

while ((i <= 5 ))
do
   eval 'a'$i'=$i'
   (( i++ ))
done

echo "$a1 $a2 $a3 $a4 $a5"