Array size in unix

June 13, 2011 at 04:50:13
Specs: unix
I have declared array in unix

a="a b c d e"

How to get the size of this array?

I tried ${#a[*]} but doesnot work kindly help...

See More: Array size in unix

Report •

June 13, 2011 at 06:27:03
First, which shell you are using? I am assuming the bash shell since this is the Linux forum. You have defined an array of one element so the length of the array:


equals one.

I am betting that you think that array a contains elements a, b, c, d, e and the length should be 5:


# syntax to declare an array of 5 elements in bash
declare -a a=(a b c d e)

echo ${#a[*]} # length should be 5

Check out this link for how to handle bash arrays:

Report •
Related Solutions

Ask Question