Forrest logo
back to the echo tool

shell:warp:49dd1

Get number of elements in an array
$ echo ${#${array_name}[@]}
try on your machine

This command is used to print the length (number of elements) of an array in Bash.

Here is how the command works:

  1. ${array_name[@]}: This is used to access all the values in the array array_name. The [@] notation treats each element in the array as a separate entity.

  2. ${#...}: This notation is used to get the length (number of characters) of a string or element. So, ${#${array_name}[@]} gives us the length of the array array_name.

  3. echo: This command is used to print the value to the terminal.

Putting it all together, the command echo ${#${array_name}[@]} prints the length of the array array_name to the terminal.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the echo tool