Mutilple variable assignment

i have file that contains data as follows

1
2
3

now i need to assign them into three variables

a1=1
a2=2
a3=3

Everything should come under a loop. In reality i may have 10 values which has to be assigned to 10 variable. if i have 25 values ( lines) , each should be assigned into 25 variables ... if someone good at array variable or dynamic variable assignment , can you please suggest on this

Here is an example

$ cat test 
1
2
3 

Variables

$ i=1; while read xx; do export a"$i"=$xx; i=$((i+1)); done < test
$ echo $a1
1

$ echo $a2
2

$ echo $a3
3

Creating Array

$ i=1; while read xx; do a[$i]=$xx; i=$((i+1)); done < test

Accessing Array

$ for i in ${a[@]}; do echo $i; done
1
2
3
$ i=1; while [ ${#a
[*]} -ge $i ]; do echo ${a[$i]}; i=$((i+1)); done
1
2
3

1 Like

it works.. You guys rocks !

If running bash, check its man page for the mapfile / readarray command.