Execute multiple shell scripts concurrently

前端 未结 5 683
Happy的楠姐
Happy的楠姐 2020-12-15 08:56

I want to do the following things:

  • Execute multiple shell scripts (here 2 scripts) concurrently.

  • Wait until both scripts finish

5条回答
  •  旧巷少年郎
    2020-12-15 09:37

    Backticks do not give the value returned by the command, but the output of the command. To get the return values:

    #!/bin/sh
    
    ./a.sh &
    ./b.sh
    ret2=$?   # get value returned by b.sh
    wait %1   # Wait for a.sh to finish
    ret1=$?   # get value returned by a.sh
    echo "$ret1: $ret2"
    

    If you mistated the question and do in fact want the output of the commands, you get that as well since they will both go to the stdout of the script.

提交回复
热议问题