Using brace expansion to create lists

suggest change

Bash can easily create lists from alphanumeric characters.

# list from a to z    
$ echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z
    
# reverse from z to a
$ echo {z..a}
z y x w v u t s r q p o n m l k j i h g f e d c b a

# digits
$ echo {1..20}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
    
# with leading zeros
$ echo {01..20}
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
    
# reverse digit
$ echo {20..1}
20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
   
# reversed with leading zeros
$ echo {20..01}
20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01

# combining multiple braces
$ echo {a..d}{1..3}
a1 a2 a3 b1 b2 b3 c1 c2 c3 d1 d2 d3

Brace expansion is the very first expansion that takes place, so it cannot be combined with any other expansions.

Only chars and digits can be used.

This won’t work: echo {$(date +$H)..24}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents