Syntax

Bash For Loop over a List Syntax

In Bash, for loop over a list: loops over words or files — for f in *.txt; do echo "$f" done

Quick Answer

Syntax
for f in *.txt; do echo "$f" done
BashSyntax

For Loop over a List

Code example
for f in *.txt; do echo "$f" done

Loops over words or files.

Learn More

How to for loop over a list in Bash

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

Bash For Loop over a List Syntax

Use for f in *.txt; do echo "$f" done.

Related Syntax References

Frequently asked questions

What is the Bash syntax for for loop over a list?

Use this pattern: for f in *.txt; 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