Syntax

Bash Array Length Syntax

In Bash, array length: gets the number of array elements — ${#fruits[@]}

Quick Answer

Syntax
${#fruits[@]}
BashSyntax

Array Length

Code example
${#fruits[@]}

Gets the number of array elements.

Learn More

How to array length in Bash

  1. Open your Bash file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Bash Array Length Syntax

Use ${#fruits[@]}.

Related Syntax References

Frequently asked questions

What is the Bash syntax for array length?

Use this pattern: ${#fruits[@]}

Can I copy this Bash code example?

Yes. Use Copy code and adapt the example to your program.

Is this Bash syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify