- Southampton, England
Shell Brace Expansion
I've only just discovered brace expansion in the shell. How had I not known about this before? Somehow I've never seen someone using this clever time saving trick on the command line.
I have a subdirectory
. It contains old-file.txt
. I need to copy it to new-file.txt
. I've spent years typing:
When instead I should have been using:
Or even more succinct:
Syntax
i. [preamble]{comma,separated,strings}[postscript]
ii. [preamble]{x..y[..incr]}[postscript]
The braces may contain a set of comma-separated strings or a sequence expression. preamble
and postscript
are optional.
The comma-separated sequence {aa,bb,cc}
becomes aa bb cc
. While the sequence expression {1..10}
becomes 1 2 3 4 5 6 7 8 9 10
. The sequence also takes an optional increment value. So, {1..10..2}
expands to 1 3 5 7 9
Examples
How to create a backup of file.txt
. Easy:
Create five new directories within subdirectory: