Brace Expansions

Sometimes you may want to generate permutations of strings, which is typically used to shorten the amount of characters you need to type when specifying multiple arguments. This can be achieved through the use of braces, where braced tokens are comma-delimited and used as infixes. Any non-whitespace characters connected to brace expansions will also be included within the brace permutations.

NOTE: Brace expansions will not work within double quotes.

echo filename.{ext1,ext2}
filename.ext1 filename.ext2

Multiple brace tokens may occur within a braced collection, where each token expands the possible permutation variants.

echo job_{01,02}.{ext1,ext2}
job_01.ext1 job_01.ext2 job_02.ext1 job_02.ext2

Brace tokens may even contain brace tokens of their own, as each brace element will also be expanded.

echo job_{01_{out,err},02_{out,err}}.txt
job_01_out.txt job_01_err.txt job_02_out.txt job_02_err.txt

Braces elements may also be designated as ranges, which may be either inclusive or exclusive, descending or ascending, numbers or latin alphabet characters.

echo {1..10}
echo {10..1}
echo {1...10}
echo {10...1}
echo {a..d}
echo {d..a}
echo {a...d}
echo {d...a}
1 2 3 4 5 6 7 8 9
10 9 8 7 6 5 4 3 2
1 2 3 4 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
a b c
d c b
a b c d
d c b a

It's also important to note that, as range brace expansions return arrays, they may be used in for loops.

for num in {1..10}
    echo $num
end
1
2
3
4
5
6
7
8
9