I have a function foo which takes one argument and get result by some calculation.
foo(){
# do some calculation
sleep 10s
echo result
}
I need to execute a function several times. Each time of execution takes some time and is independent so I want to do this in parallel.
result1=$(foo arg1)&
result2=$(foo arg2)&
result3=$(foo arg3)&
result4=$(foo arg4)&
However, the result variables are empty after invoking the function. How can I get the result value correctly?