Zsh is cool : brace expansion

July 12th, 2007 by Stephane Kattoor

Quoting the zshexpn man page :

 

An expression of the form {n1..n2}, where n1 and n2 are integers, is expanded to every number between n1 and n2, inclusive. If either number begins with a zero, all the resulting numbers will be padded with leading zeroes to that minimum width. If the numbers are in decreasing order the resulting sequence will also be in decreasing order.

Check out this :

spaghetti% for i in {8..11}; do echo $i; done
8
9
10
11
spaghetti%

and then this :

spaghetti% for i in {08..11}; do echo $i; done
08
09
10
11
spaghetti%

So much for the “while loops” with expr to increment a variable and “if” tests to add the padding zeroes :-)


Most Commented Posts

2 Responses to “Zsh is cool : brace expansion”

  1. Zsh is cool : stream redirections - Tech@Sakana Says:

    [...] If you liked this article about Zsh, then you might be interested in my previous article about brace expansion in zsh. [...]

  2. Unix Mouth » Brace expansion in ZSH Says:

    [...] read more | digg story [...]

Leave a Reply