Here\'s an example program:
#!/bin/bash for x in {1..5} do output[$x]=$(echo $x) & done wait for x in {1..5} do echo ${output[$x]} done
If you want to avoid writing files, you can use GNU parallel:
GNU parallel
#!/bin/bash output=(`parallel -k --gnu echo {1} ::: {1..5}`) for i in ${output[@]} do echo $i done
The -k is to preserve the order of the output
-k