How do I run a sequence of commands in parallel, and store their output in a variable?
I've tried:
output=`(echo -n "started "; sleep 2; echo "stopped") &`
echo "output before=$output"
wait
echo "output after=$output"
And got a pause of two seconds, followed by:
output before=started stopped
output after=started stopped
I expected:
output before=
<2 seconds pause>
output after=started stopped
How do I run a sequence of commands in the background, and store their output in a variable?
()is executed on background, so you get its output once everything is finished. Hence, thesleepis "hidden" to you.