4 ms·
Another very useful feature related to brace expansion are sequences: {1..99} will give 1 2 3 4 5 .. 9 10 11 12 .. 98 99 {01..99} will give 01 02 03 04 05 ..
by js8 10y ago
Another very useful feature related to brace expansion are sequences:
{1..99} will give 1 2 3 4 5 .. 9 10 11 12 .. 98 99
{01..99} will give 01 02 03 04 05 .. 09 10 11 12 .. 98 99
And so on. I think it also works with letters.
- 0xmohit 10y agoBrace expansion can also be nested: $ echo {a..c}{1..5} a1 a2 a3 a4 a5 b1 b2 b3 b4 b5 c1 c2 c3 c4 c5 It is worthwhile noting that brace expansion is strictly textual and is performed before any other expansion.
- FoeNyx 10y ago> I think it also works with letters. Indeed it does. According to the man page : "When characters are supplied, the expression expands to each character lexicographically between x and y, inclusive, using the default C locale." $ 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 But it does not seem to work with ranges outside ASCII such as "à..é", "あ..お", or smileys range, even though my locale should be ".UTF-8" compliant. Also, you can specify an increment value : $ echo {0..42..7} 0 7 14 21 28 35 42 $ echo {z..a..3} z w t q n k h e b
- coldpie 10y ago> Indeed it does. According to the man page : "When characters are supplied, the expression expands to each character lexicographically between x and y, inclusive, using the default C locale." I think 'x' and 'y' are probably the worst variable names they could have chosen for this sentence :)
- mturmon 10y agoThanks. And as your last example illustrates, downward ranges are automatically invoked: $ echo {10..1} 10 9 8 7 6 5 4 3 2 1 As are negative endpoints (shown below with some automatic number formatting, which is turned on when either the first or the second endpoint is padded): $ echo {2..-002} 0002 0001 0000 -001 -002 I just noticed that all this is documented behavior -- another illustration of how rococo this shell has become.