Execute curl requests in parallel in bash

curlmulti-coresmpwget

What is the best way to execute 5 curl requests in parallel from a bash script? I can't run them in serial for performance reasons.

Best Answer

Use '&' after a command to background a process, and 'wait' to wait for them to finish. Use '()' around the commands if you need to create a sub-shell.

#!/bin/bash

curl -s -o foo http://example.com/file1 && echo "done1" &
curl -s -o bar http://example.com/file2 && echo "done2" & 
curl -s -o baz http://example.com/file3 && echo "done3" &

wait