6

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!

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Firegun
  • 1,829
  • 3
  • 15
  • 9

1 Answers1

7

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/

Gilles Quénot
  • 31,569
  • 7
  • 64
  • 82