Bash run two commands and get output from both [cl

2019-09-21 09:53发布

I need to run two command in parallel and get the output from both in the same shell.

Edit:

I am trying to run multiple long-running commands that watch the file system and compile various things for me(coffeescript, jade, sass).

标签: bash shell
2条回答
SAY GOODBYE
2楼-- · 2019-09-21 09:59

You're probably looking at wait command in bash. Consider this script:

#!/bin/bash

FAIL=0
echo "starting"

./script1 &
./script2 &

for job in `jobs -p`
do
   echo $job
   wait $job || let "FAIL+=1"
done

echo $FAIL

if [ "$FAIL" == "0" ];
then
    echo "All jobs completed!"
else
    echo "Jobs FAILED: ($FAIL)"
fi

Courtesy

查看更多
乱世女痞
3楼-- · 2019-09-21 10:19
command1 &
command2 &

They're both running in parallel; their output goes to the screen.

查看更多
登录 后发表回答