更新:感谢你指出另一个重复的问题和@CharlesDuffy的评论。我的问题可以这样解决:
#!/bin/bash
APPS="app1 app2"
LIBS="lib1 lib2"
PROJECTS="${APPS} ${LIBS}"
projects=()
for project in $PROJECTS
do
projects+=("ng lint ${project}")
done
./node_modules/.bin/npm-run-all -p "${projects[@]}"
另一种等待方式:
#!/bin/bash
APPS="app1 app2"
LIBS="lib1 lib2"
PROJECTS="${APPS} ${LIBS}"
FAIL=0
pids=()
for project in $PROJECTS
do
ng lint "${project}" & pids+=( "$!" )
done
for pid in "${pids[@]}"
do
wait "${pid}" || FAIL=$(( FAIL + 1 ));
done
if [ "$FAIL" != "0" ];
then
exit 1
fi