Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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.

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
up vote 6 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 – Gilles Quenot Oct 31 '12 at 3:12
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

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