How do I write a script to run multiple processes in the background and have additional commands run once each individual command completes?
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.
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
精彩评论