If I want a 2D bash array, is there any recommended way of doing this for say, a N x M arrangement? On several occasions, I've had to define array1, array2, arrayN each of M elements in conjunction with case statements - but this is very clumsy.
I realise it would be possible to define a single big array X and compute a 1-1 map between X[something] and the [i,j] element - but this seems like a lot of work to do it properly.
Does there exist any set of functions which could do this reasonably efficiently? I realise its a bit like making Bash imitate FORTRAN.
declare -A a; i=2; j=3; a[$i,$j]=4; echo ${a[2,3]}. Of course, nicely iterating through rows and cols will be a bitch. But if you need to handle complex data structures, using bash is certainly not the best idea.declare -a a; i=2; j=3; a[i<<16|j]=4; echo ${a[2<<16|3]}(assuming that 65536 x 65536 is enough for everybody ;-)).a[1<<30]=foowill NOT allocate 1G of empty slots. And like everything in bash, they're also very slow ;-)a(i,j) == a[i*ncols + j]or similar transformation? This is a common way to do it when managing 1D structures is easier (or more efficient) than managing multi-D structures.