(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Kerio Reseller
Printer Friendly Version

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



Hate these ads?

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;done







This 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-done


and 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.



Comments /Linux/brace-expansion.html


Mon Oct 3 07:31:46 2005: Subject:   drag
Oh.. that's nice. (I am sure somebody will come along and point out that ksh or other 'alternative' shell had it first, but still this is cool) :P





Mon Oct 3 13:09:30 2005: Subject: nested expansion was knowledge   infinity
never knew that this kind of facility was available.


thanks!

Mon Oct 3 13:20:49 2005: Subject:   TonyLawrence
Well, nested brace expansion has worked before now, but the list expansion in braces is new. Combining both is pretty darn powerful as you see above..



Add your comments

Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)

Or use any RSS reader

Delivered by FeedBurner


ad

Views for this page
Today This Week This Month This Year  Overall
21835947 3,661

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

pavatar.jpg
More:
       - Linux
       - Unix
       - MacOSX
       - Shell




Unix/Linux Consultants

Your ad here - $24.00 yearly!

http://echo3.net/ Unix/Linux Custom Applications, Web Hosting, C/C++ Programming Courses


http://bcstechnology.net Full service Linux & UNIX systems integrator; Windows to UNIX/Linux Client-Server Specialist; Secure E-Mail & Website Hosting; Thoroughbred Software Developer; Custom Industrial Automation; Hardware & Electronics Experts; In Business Since 1985.


larryi@ccamedical.com SCO OS5, Debian Linux, RedHat Linux, MySQL, Apache, AJAX development using dXport/dL4/Unibasic, Windows Connectivity, Sharing Resouces, Automation, Shell Scripting







Coming Attractions

My Favorites

Change Congress


Related Posts