1

I saw lots of article on this. The most useful for me was this one

How to declare 2D array in bash

the answer seems really useful since he got 20 likes. However I can't see what I do different (except my array isn't set in a loop)

matrix[0,0]=2
matrix[0,1]=1
matrix[1,0]=9
matrix[1,1]=8
matrix[1,2]=7

echo ${matrix[0,0]}
echo ${matrix[0,1]}
echo ${matrix[1,0]}
echo ${matrix[1,1]}
echo ${matrix[1,2]}

I get 9 8 9 8 7

Community
  • 1
  • 1
Cher
  • 2,789
  • 10
  • 37
  • 64

1 Answers1

0

You're missing the variable declaration as an associative array via -A:

typeset -A matrix

Without that, you seem to get a normal array, and then only the last index is actually used; that explains the (wrong) results you've got.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324