0

I used the array assignment below in order to simulate a two dimensional array:

for((i=0;i<2;i++))        
do        
    for((j=0;j<3;j++))        
    do        
        read TWOD$i[$j]        
    done        
done < hi.txt

The file hi.txt contains these lines:

 1    
 2    
 3    
 4     
 5    
 6

If I use echo ${TWOD0[2]}, I can print the value 2, but if I am using a variable for the first index, bash throws a syntax error bad substitution:

 for((i=0;i<2;i++))    
 do    
     printf "%s\n" "${TWOD$i[2]}"    
 done

Is there any way to extract the elements from the array using a variable for the first index?

4

1 に答える 1