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.