How does one wait for multiple background jobs to complete before continuing with a process?


For example, I want to get five files from the internet and then cat them together. In serial mode:

for i in 1 2 3 4 5;
  wget http://foo.com/path/to/file/file$i
done
cat file{1,2,3,4,5} > one big.file.txt

While the above works, it could be made faster if I could do the wgets in parallel, like so:

for i in 1 2 3 4 5;
  wget http://foo.com/path/to/file/file$i &
done

However, I somehow have to wait at the end of the loop for the last job to finish before starting the cat. How can I do that? In pseudocode:

for i in 1 2 3 4 5;
  wget http://foo.com/path/to/file/file$i &
done
wait-for-last-job-to-finish
cat file{1,2,3,4,5} > one big.file.txt

I'm experimenting with the wait command in bash. Will see how that goes.

Regards,
- Robert
http://www.cwelug.org/downloads
Help others get OpenSource.  Distribute FLOSS for
Windows, Linux, *BSD, and MacOS X with BitTorrent

_______________________________________________
CWE-LUG mailing list
http://www.cwelug.org/ [EMAIL PROTECTED]
http://lists.firepipe.net/listinfo/cwe-lug

Reply via email to