How to get the size of the second dimension of two dimensional arrays in bash?
2 answers
Bash doesn't have a multidimensional array. What you are trying to do will not even simulate a multidimensional array unless you have declared the variable arr
as an associative array. Check out the following test:
#!/bin/bash
arr[0,0]=0
arr[0,1]=1
arr[1,0]=2
arr[1,1]=3
echo "${arr[0,0]} ${arr[0,1]}" # will print 2 3 not 0 1
unset arr
declare -A arr
arr[0,0]=0
arr[0,1]=1
arr[1,0]=2
arr[1,1]=3
echo "${arr[0,0]} ${arr[0,1]}" # will print 0 1
And you can only get the size in general with ${arr[@]}
0
source to share