Quick post for my own reference down the road. the “for” loop comes in very handy, when you want to perform the same task on multiple items in a bash shell.
For example, I wanted to query the DNS results of a couple of sub domains (blog.gogoair.com, pr.gogoair.com, tracker.gogoair.com), I can do it the normal way (that 99% of us do 🙂 )
[code] dig blog.gogoair.com
dig pr.gogoair.com
dig tracker.gogoair.com [/code]
Or, I can use the for loop function and do this
[code] for i in {blog,pr,tracker}.gogoair.com; do echo "$i" ; dig +short "$i"; done [/code]
Got to love technology :).. Makes you lazy!!..err I meant to say productive.
Thx to Cliff for the inspiration.
Nice. The expansion feature of the shell really makes for loops come to life. Things like webserver0{1,3,5) or database0{1..7} just bring a smile to my face.
If you ever want more examples I’ll be happy to send you some. You might find some inspiration in my .shrc as well at: http://fossil.secution.com/u/gcw/dotfiles/dir?ci=tip
–Cliff