Multiple indexed conditions with ksh

Dear Unix Experts,

I have randomly generated the x, y, and z coordinates of 16 atoms of two species, A and B (8 atoms each) Then I calculated the spacing between all the A atoms labeled d1, B atoms labeled d2 and between A and B atoms labeled d3. I would like to save the x, y, z coordinates to a file (output) if d1 are between a1 and b1, d2 are between a2 and b2, and d3 between a3 and b3, where a's and b's are integers. Otherwise, new random coordinates are generated until the above multiple conditions are met.
For checking the above conditions, I have tried the following (in ksh):

i=1
while [ $j -le 8 ]; do
j=1
while [ $j -le 8 ]; do
if [ "${d1[$j][$i]}" -gt a1 ] && [ "${d1[$j][$i]}" -lt b1 ] && [ "${d2[$j][$i]}" -gt a2 ] && [ "${d2[$j][$i]}" -lt b2 ] && [ "${d3[$j][$i]}" -gt a3 ] && [ "${d3[$j][$i]}" -lt b3 ]; then
echo ${xA[$i]} ${yA[$i]} ${zA[$i]} >> output
echo ${xB[$i]} ${yB[$i]} ${zB[$i]} >> output
fi
let "j +=1"
done
let "i +=1"
done

Putting the echo command in the loop clearly doesn't work but I cannot put it outside the loop either. I know there must be other ways to do this. I would really appreciate your input.

Many thanks,
Vahid

I Don't think 2 dimensional arrays are supported in ksh.

1 Like