Zsh is cool : brace expansion

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 🙂

2 thoughts on “Zsh is cool : brace expansion”

Comments are closed.