Friday, March 28, 2008

Brace Expansion

A little known feature of bash is brace expansion. Brace expansion expands the items within the braces to the arguments adjacent to the brace.

Quick example:

echo foo{bar,car}
# yields
foobar foocar

What's the point?

You can use brace expansion in your shell scripts or for quick one-liners. An example:

cp foo.c{,.blah} # backup foo.c to foo.c.blah

1 comment:

Anonymous said...

Rather nice blog you've got here. Thanx for it. I like such topics and anything that is connected to them. I would like to read a bit more on that blog soon.

Best wishes
Darek Wish