The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to call two programs simultaneously vipinccmb UNIX for Dummies Questions & Answers 1 08-11-2008 02:48 AM
How to parse 2 files simultaneously Awanka Shell Programming and Scripting 8 04-12-2007 09:00 PM
cp & mkdir simultaneously enuenu UNIX for Dummies Questions & Answers 5 03-13-2007 05:29 AM
Execution of two jobs simultaneously rinku11 Shell Programming and Scripting 8 03-15-2006 01:26 AM
Running 2 apaches simultaneously sx3v1l_1n51de SUN Solaris 2 07-22-2005 11:56 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-22-2009
fedora fedora is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 94
run serveral loops simultaneously?

Hello everyone, say I have the following script, which contains serveral loops, if I run the script, it executes the loop one by one (after the a loop, it goes to b loop, then c, then d)

I figured I should be able to run all the loops at same time, but I don't know how, can anyone help a little bit here? thanks!

for file in `ls a*`; do commanda ; done

for file in `ls b*`; do commandb ; done

for file in `ls c*`; do commandc ; done

for file in `ls d*`; do commandd ; done
  #2 (permalink)  
Old 01-22-2009
Rhije Rhije is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 103
The best location for advanced topics! Special Characters

Anyways, that link will show you, but here is the code:


Code:
for i in 1 2 3 4 5 6 7 8 9 10            # First loop.
do
  echo -n "$i "
done & # Run this loop in background.
       # Will sometimes execute after second loop.



That will allow you to put the loop in the background (notice the & after done).
That should work!
  #3 (permalink)  
Old 01-22-2009
cfajohnson's Avatar
cfajohnson cfajohnson is online now Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,378
Quote:
Originally Posted by fedora View Post
Hello everyone, say I have the following script, which contains serveral loops, if I run the script, it executes the loop one by one (after the a loop, it goes to b loop, then c, then d)

I figured I should be able to run all the loops at same time, but I don't know how, can anyone help a little bit here? thanks!

for file in `ls a*`; do commanda ; done

for file in `ls b*`; do commandb ; done

for file in `ls c*`; do commandc ; done

for file in `ls d*`; do commandd ; done

Not only is ls unnecessary, but it will break your script if any of the filenames contain spaces.


Code:
for file in a*; do commanda ; done &
for file in b*; do commandb ; done &
for file in c*; do commandc ; done &
for file in d*; do commandd ; done &

Or:


Code:
for l in a b c d
do
   for file in "$l"*; do command$l; done *
done

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:43 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0