5
1
I'd like to write a loop ('for') that will do some action 'X' number of times. But instead of performing the actions sequentially, one after another, I'd like them to execute simultaneously (in parellel at the same time). How can this be achieved? Script or a one liner are fine.
example ONLY:
for i in 1 2 3 4 5; do dd if=/dev/zero of=/tmp/disk$i bs=10M count=10; done
Since the OP tagged the question with Bash, you don't have to use
seq
. You can either do it as shown in the question or one of these ways:for i in {1..5}
(Bash >= 3.0) orfor ((i=1; i<=5; i++))
(Bash >= 2.04). However, for compatibility with other shells,seq
can be used, unless you're on a BSD system such as FreeBSD or OS X, then you need to usejot
. – Paused until further notice. – 2010-05-17T13:42:39.887@Dennis, that quite collects the range options :-). I used
seq
from habit mostly... thefor
loops are good;seq
lets you format easily, which may be the reason my mind sticks to it. – nik – 2010-05-17T15:55:40.960I want to make my scripts portable (POSIX) so they can be used on as many systems as possible. I'll go with
seq
. Thanks to all respondents. – Felipe Alvarez – 2010-05-18T08:12:48.947