Bash 3.00 brace expansion
By Tony Lawrence2005-10-04
Bash 3.00 brace expansion
Ah, finally: no more of
for i in 1 2 3 4 5 6 7 8 9 0
do
.. whatever
done
With Bash 3.0, we now have brace expansion for lists:
for i in {1..10} ; do echo $i ; done
Prior to this, we sometimes used "seq", which could result in such awful things as:
for i in `seq 65 69`; do echo -e `printf '\\%03o' $i`; done
Ugly. The Bash 3.0 way is so much cleaner:
for i in {A..E}; do echo $i;doneThis also works for more traditional brace expansion use:
$ echo foo{1..4}bar
foo1bar foo2bar foo3bar foo4bar
# used to be done as
$ echo foo{1,2,3,4}bar
foo1bar foo2bar foo3bar foo4bar
Nesting of course still works:
echo foo{bar{1..3},-is-done}
foobar1 foobar2 foobar3 foo-is-doneand you can use it for such tasks as:
mkdir {A..D}{1..3}{0-9}which would have required nested loops before Bash 3.0
Tutorial pages:
|
© Copyright 2005 A.P. Lawrence
|
|||||||||
You might also want to check these out:
|
Leave a Comment on "Bash 3.00 brace expansion"
You must be logged in to post a comment.
Link to This Tutorial Page!

