Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Possible Duplicate:
Parallelizing a for loop

The original code might look like this:

 for i in *; do something.py $i; done

I was wondering whether I can run these jobs parallelly in the backgroud, such as:

 for i in *; do something.py $i &; done

I tried and found the & here won't work..

Moreover, a better way might be that bash allow 8 jobs(or any number) run together in the queue in background, but I don't know how to do that...

Does anyone have ideas about this? Thanks!

share|improve this question
    
I would just do this in Python, anyway. –  Keith Oct 31 '12 at 4:29
    
Not very much a duplicate, that one doesn't concern the problem with & though –  warl0ck Oct 31 '12 at 8:49
add comment

marked as duplicate by jasonwryan, Mat, Renan, Stéphane Gimenez, Gilles Oct 31 '12 at 22:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

up vote 5 down vote accepted

Simply remove the ; character, so in final :

 for i in *; do something.py $i & done

And for running N instance of your script at the same time, see man 1 parallel

See http://www.gnu.org/software/parallel/

share|improve this answer
    
Added some hints about parallel –  sputnick Oct 31 '12 at 3:12
1  
It isn't necessary to comment after editing a post: its a wiki, the edit history is recorded... –  jasonwryan Oct 31 '12 at 4:06
    
Interesting, you don't need the semicolon before done –  warl0ck Oct 31 '12 at 8:48
    
& is a command terminator like ; and newline: also && and ||. See SHELL GRAMMAR in the bash manpage, or here –  glenn jackman Oct 31 '12 at 13:40
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.