Skip to main content
Removed linux tag and improved formatting.
Source Link

BASH - 2-D 2D bash arrays -: is this possible?

If I want a BASH 2D bash array, is there any recommended way of doing this for say, a N x MN x M arrangement? On several occasions, I've had to define array1array1, array2array2, arrayNarrayN each of MM elements in conjunction with case statements - but this is very clumsy.

I realise it would be possible to define a single big array XX and compute a 1-1 map between X[something]X[something] and the [i,j][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 BASHBash imitate FORTRAN.

BASH - 2-D arrays - is this possible?

If I want a BASH 2D 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.

2D bash arrays: is this possible?

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.

edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 264
Source Link
Jeremy Boden
  • 1.3k
  • 12
  • 23

BASH - 2-D arrays - is this possible?

If I want a BASH 2D 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.