Syntax

Bash Loop over an Array Syntax

In Bash, loop over an array: loops over every array element — for f in "${fruits[@]}"; do echo "$f"; done

Quick Answer

Syntax
for f in "${fruits[@]}"; do echo "$f"; done
BashSyntax

Loop over an Array

Code example
for f in "${fruits[@]}"; do echo "$f"; done

Loops over every array element.

Learn More

How to loop over an array in Bash

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

Bash Loop over an Array Syntax

Use for f in "${fruits[@]}"; do echo "$f"; done.

Related Syntax References

Frequently asked questions

What is the Bash syntax for loop over an array?

Use this pattern: for f in "${fruits[@]}"; do echo "$f"; done

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