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.
Share:
12,734

Related videos on Youtube

kickass27
Author by

kickass27

Updated on September 18, 2022

Comments

  • kickass27
    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.