Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Found this nifty lifehacking gem to create multiple directories: http://unix.stackexchange.com/a/640/7768

I was wondering if there are other commands support brace expansion?

share|improve this question
3  
As explained in the answers there, brace expansion is a feature of the shell. What else do you need? –  Stéphane Gimenez Dec 2 '11 at 16:43

2 Answers 2

up vote 9 down vote accepted

The braces are a shell expansion, so you can use them with any command. For the record, it doesn't have to be .., and it doesn't have to be letters. Numbers work with a range, you can use commas for independent values, and you can mix it with regular tokens or other expansions:

$ echo {1..3} {a..c} {1..3}-{a,c}
1 2 3 a b c 1-a 1-c 2-a 2-c 3-a 3-c

And you can nest, which I often use for installing/uninstalling ({,un}installing :) ) packages.

aptitude install package{,-{dev,doc}}

which expands to

package package-dev package-doc
share|improve this answer
2  
+1 for the package trick. –  Sachin Divekar Dec 2 '11 at 19:29

Further more, it can even have regular expressions. A correctly-formed brace expansion must contain unquoted opening and closing braces, and at least one unquoted comma or a valid sequence expression. Any incorrectly formed brace expansion is left unchanged. Example:

mkdir /usr/local/src/bash/{old,new,dist,bugs}
chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}

http://www.gnu.org/s/bash/manual/html_node/Brace-Expansion.html

http://www.linuxjournal.com/content/bash-brace-expansion

share|improve this answer
    
Can it be used to copy a single file to multiple targets? –  chrisjlee Dec 2 '11 at 19:45
    
@ChrisJ.Lee No, not with cp, because cp only supports a single target. Braces are a way to pass several names to one command without having to write each name in full separately. They know nothing about files and such. –  Gilles Dec 2 '11 at 23:22
    
Thanks @Gilles. Good to know –  chrisjlee Dec 3 '11 at 5:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.