Bash Loops

Here’s a basic loop in Bash:

Notice that it iterates over a space delimited string of values.

If you have a comma delimited list then you can do something like this:

IFS is the “internal field separator” which defaults to a blank space. We save the original IFS and change it to a comma. Then once we’re done we restore the original IFS.

Here are some links to additional examples:

http://www.cyberciti.biz/faq/bash-for-loop/

http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-7.html

http://www.thegeekstuff.com/2011/07/bash-for-loop-examples/

Have a project or a problem?

Talk with a senior engineer for practical recommendations—no obligation.

Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Categories

Get a free consultation from Reliable Penguin

Submit the form—or for immediate service call 866-649-7984.