03 Dec 2009
Bash is a wonderful fully featured shell that provides a multitude of ways to cut back on your keystrokes. One of my favorite features, which I don’t see used often enough, is brace expansion. Simply put, brace expansion lets you specify multiple similar arguments without retyping the commonalities. Let’s take a look at how this is accomplished.
With this handy feature, you can do a multitude of things. You can make a backup copy of a file:
Then you can restore that file:
Obviously, it doesn’t stop here. You can make a whole directory structure:
Bash will expand ranges as well. You can create a zero padded range like so:
Ranges aren’t limited to being numerical. Better yet, expressions can be the preamble and postscript to each other.
If you really use your noodle you can nest expressions, though I’ve personally not come across a situation where this has been needed (yet).
blog comments powered by Disqus