2022-12-01

Brace expansion

Brace expansion on Wiki

Tweet from Wes Bos

Examples

❯ echo {1,2,3} 1 2 3
# Spaces are not allowed echo {1, 2, 3} zsh: parse error near `}'
❯ echo file{1,2,3} file1 file2 file3
❯ echo file{,2,3} file file2 file3
❯ echo file{1..3} file1 file2 file3
❯ echo file{001..3} file001 file002 file003
# Nested ❯ echo file{1,2{a,b},3} file1 file2a file2b file3
❯ mkdir -p settings/{__init__,base,local} ❯ tree . └── settings ├── __init__ ├── base └── local
❯ mkdir -p parent/{girl,boy}/{name,age} ❯ tree . └── parent ├── boy │   ├── age │   └── name └── girl ├── age └── name
❯ touch 11.{in,py} ❯ tree . ├── 11.in └── 11.py
❯ touch post_2022_{01..3}.md ❯ tree . ├── post_2022_01.md ├── post_2022_02.md └── post_2022-03.md
❯ touch test.js ❯ cp test{,_copy}.js ❯ tree . ├── test.js └── test_copy.js
❯ touch test.txt ❯ mv test.{txt,md} ❯ tree . └── test.md
❯ mv {,parent/}folder ❯ tree . └── parent    └── folder
❯ curl https://httpstat.us/{417..418} 417 Expectation Failed418 I'm a teapot%