LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Two dimensional array (https://www.linuxquestions.org/questions/programming-9/two-dimensional-array-610284/)

som_kurian 12-31-2007 11:13 PM

Two dimensional array
 
Is it possible to write a Two dimensional array in bash script..If Yes then can you guys give me an example to do this..I tried one dimensional array.Is it in the similar way

jozyba 01-01-2008 03:13 AM

No, you can only have one-dimentional arrays in bash, but there's an interesting post from comp.unix.shell by Chris F.A. Johnson on how to emulate a two-dimentional array:
http://www.dbforums.com/archive/index.php/t-364801.html

SeRGeiSarov 01-01-2008 03:27 AM

May be
Code:

#!/bin/sh
i=5
j=6
for ((k=0;k<$((i*j));k++))
do
  FOO[k]=$k
done

for ((m=0;m<$i;m++))
do
  for ((n=0;n<$j;n++))
  do
    echo ${FOO[$((m*j+n))]}
  done
done



All times are GMT -5. The time now is 01:56 AM.