parameter-expansion

Bash array element count

Counts assigned elements, including empty strings, rather than the highest index.

Formal Syntax & Structure

bash syntaxbash
${#name[@]}

Return Value

integer

Counts assigned elements, including empty strings, rather than the highest index.

Working Example

Example Snippetbash
items=([0]=alpha [5]=omega)printf 'count=%s\n' "${#items[@]}"for i in "${!items[@]}"; do  printf '%s=%s\n' "$i" "${items[i]}"done
Bash Reference