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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.