Last Updated: July 16, 2020
·
1.715K
· walkeran

BASH brace expansion gone wild

Of course, you can use brace expansion in bash to do simple things like
$ echo {1,2,3}
1 2 3

But, did you know, you can also combine multiple expansions?
$ echo {1,2,3}{a,b,c}
1a 1b 1c 2a 2b 2c 3a 3b 3c

And it even supports ranges using the '..' syntax!
$ echo {1..3}{a..f}
1a 1b 1c 1d 1e 1f 2a 2b 2c 2d 2e 2f 3a 3b 3c 3d 3e 3f

3 Responses
Add your response

One of my favorite applications of this:

git add Gemfile{,.lock}
over 1 year ago ·

Just keep in mind that these things are bashisms, i.e. they will not work in plain shell you might use in your scripts.

over 1 year ago ·

You can even nest them: mkdir /{,usr/{,local/}}{s,}bin

over 1 year ago ·