For loop in bash (can be used on command line or in script)

There are so many versions of Bash around and it can be frustrating, to me at least, to do some things for not knowing what is available on a given machine. Well here is one, the for loop. Here are a few different ways to do the same thing (and I am sure there are many others) . The first two below work on current linux machines but only the third works on Solaris 5.8′s version of Bash. Enjoy

for ((i=0;i<=5;i+=1));  do echo anda$i; done;
for seq 6 7;  do echo anda$i; done;
for i in 8 9 10 11 12; do cvs tag -d  anda$i; done;
About these ads

About Jayson
Father, mountain biker, Software developer at a wire service, and also work with the IPTC (iptc.org)

One Response to For loop in bash (can be used on command line or in script)

  1. Hey good tip. I wasn’t aware of the third form.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: