Bash run two commands and get output from both [cl

2019-09-21 10:18发布

问题:

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).

回答1:

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



回答2:

command1 &
command2 &

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



标签: bash shell