Count number of elements in an array
12,734
Solution 1
To count the number of elements use
${#array[@]}
.
In order to get the length of a particular element use (I'm getting the length of the 3rd element)
echo ${#array[2]}
.
Solution 2
According to the ksh man page:
${#parameter } If parameter is * or @, the number of positional parameters is substituted. Otherwise, the length of the value of the parameter is substituted.
Related videos on Youtube
Author by
kickass27
Updated on September 18, 2022Comments
-
kickass27 almost 2 years
I would like to ask if there is a way to count the number of elements in an array in
ksh
.