New shell trick

Came across a great new shell tip. Brace expansion.

Some examples:

$echo {one,two,three,four}" fish"
one fish two fish three fish four fish

$ echo {{1,2,3}1,2,3}
11 21 31 2 3

Ok, that’s great. What’s it good for:

$ cp /tmp/test.html /tmp/test.html_bak

Can be rewritten as:

cp /tmp/test.html{,_bak}

Then after you makes some changes to /tmp/test.html:

$ diff /tmp/test.html{_bak,}

Works in bash, zsh and possibly others.

3 Comments

  1. Posted March 29, 2005 at 10:35 pm | Permalink

    Brace expansion works in every shell known to me. There might be some enhanced iterative features in bash though.

    -n

  2. Posted March 30, 2005 at 1:28 pm | Permalink

    well do I remember your icon! Been to JDs lately? I remember when we went to that place all the time, then suddenly, no more!

  3. Posted March 30, 2005 at 4:54 pm | Permalink

    We make the trek at least twice a month these days.