Expand a Bash brace pattern into its full list

Expand Bash brace alternatives and sequences into their generated words.

freeworks offlinenothing uploaded
ToolBash Brace Expansion
Input
Output
Put this on your own site

The frame below runs the same code as this page, in the reader's own browser. Nothing is sent to us, and nothing is sent to you.

Pick a dark background and the text and panels follow it, so the frame stays readable on a dark page.

Preview

How it works

Comma alternatives and numeric or alphabetic sequences expand before pathname expansion, producing the Cartesian product of adjacent expressions. Generated words are literal and do not require matching files.

  • Brace expansion is an early textual shell step.
  • Quoting suppresses expansion when literal braces are needed.

Worked example

file{1..3}{a,b}.txt
A numeric range and a comma list, combined
Input
											file{1..3}{a,b}.txt
										
Output
												Expansions: file1a.txt, file1b.txt, file2a.txt, file2b.txt, file3a.txt, file3b.txt
Count: 6
Warning: 
											

When to use this

Backup loops, build scripts, and mkdir commands generate related paths.

Edge cases

  • file{a,b} expands even when the files do not exist.
  • Nested ranges can create a large Cartesian product.
  • '{a,b}' remains literal because quoting disables expansion.

References