Reputation: 23633
I'm trying to do something like the following in a bash script:
for x in a b c; do echo foo $x; sleep 5 & y=$! ; (wait $y && echo bar $x) & done
Is this possible, without adding much complexity (the above example of course does not actually work)?
EDIT:
Of course in reality, echo foo $x; sleep 5
would be for example, copying some large file or compiling something big, and the second operation would be operations that depend on the first.
Upvotes: 2
Views: 156
Reputation: 53496
Maybe I am missing something but what about using ()
s and putting the &
on the entire sub group command...
for i in 1 2 3; do (echo $i; sleep 5; echo end $i)& done
Upvotes: 6