AUWENFIELD NOTES
JOHNNY AUWENFORGE
LUMEN Galleries ↗
← Command indexBash / loop

for

Repeat commands over words.

Before running this

This is a reference for Bash; commands do not run on this page. Use the matching shell on your own computer. Read the example, expected result and notes before trying it. New to terminals? Start with the shell basics.

Syntax

UPPERCASE words are placeholders to replace. Brackets in the syntax line describe optional arguments; do not type those brackets literally.

for NAME in WORDS; do COMMANDS; done

Example

for city in Munich Bucharest; do printf "%s\n" "$city"; done

Expected result

Munich and Bucharest on separate lines.

Notes and traps

Quote variable expansions; for file in $(ls) breaks on ordinary filenames.

Related commands

Related tasks may need different flags and have different semantics. Check the entry before translating a command between shells.

Official reference ↗

Updated 13 September 2026. Examples describe the expected behavior; not every platform is available for execution testing.