[Bash] Get the number of elements in an array

Created on November 28, 2026

For example, if your array is named someArray, you can get its number of elements with ${#someArray[@]}.

#! /bin/bash

someArray=(a b c d e)
length=${#someArray[@]}
echo $length

The script produces the following output.

5
Bash