tags:

views:

171

answers:

2

How to find the array length in unix shell?

+2  A: 

Assuming bash:

~> declare -a foo
~> foo[0]="foo"
~> foo[1]="bar"
~> foo[2]="baz"
~> echo ${#foo[*]}
3

So, ${#ARRAY[*]} expands to the length of the array ARRAY.

unwind
+1  A: 
$$ a=(1 2 3 4)
$$ echo ${#a[@]}
4