Bash & (ampersand) operator

后端 未结 4 667
轮回少年
轮回少年 2020-12-14 02:52

I\'m trying to run 3 commands in parallel in bash shell:

$ (first command) & (second command) & (third command) & wait

The prob

4条回答
  •  無奈伤痛
    2020-12-14 03:36

    the best I can think of is:

    first & p1=$!
    second & p2=$!
    ...
    
    wait $p1 && wait $p2 && ..
    

    or

    wait $p1 || ( kill $p2 $p3 && exit 1 )
    ...
    

    however this still enforces an order for the check of processes, so if the third fails immediately you won't notice it until the first and second finishes.

提交回复
热议问题