Web Analytics

Brace Expansion

Advanced~15 min read

Brace expansion builds lists before command execution, useful for ranges, permutations, and templated names.

Examples

Output
Click Run to execute your code
Note: Expansion happens in the shell, not by external commands.
Pro Tip: Use zero-padded ranges like {01..12} to align filenames.
Caution: Globbing may expand further; quote paths to avoid unintended matches.

Common Mistakes

1) Expecting runtime evaluation

Brace expansion is purely syntactic; it does not evaluate variables inside braces.

2) Missing braces

Use braces, not parentheses, and separate list items with commas.

Exercise: Month Files

Task: Echo the sequence report_01.txt to report_12.txt using brace expansion.

Output
Click Run to execute your code
Show Solution
echo report_{01..12}.txt

Summary

  • Generate ranges and lists with braces.
  • Use zero-padding for aligned names.
  • Quote to control globbing.

What's Next?

Unlock powerful string operations via Advanced Parameter Expansion.