在第一次迭代后在循环中运行“node app.js”

时间:2017-10-02 17:49:36

标签: bash macos shell

我正在玩第一次编写脚本,并希望循环并启动一些node.js应用程序。每次我开始第一个应用程序虽然循环中断。

我已经搜索了一段时间来获得解决方案并查看用于-nssh并使用</dev/null创建新终端的(command)标记命令。也许答案就在于这些,但我没有看到它。

非常感谢任何帮助。谢谢!

for A in "${ARR[@]}"
do
    case $A in
        $APP1)
            DIR=$APP1_DIR; FILE=$APP1_FILE;
            ;;
        $APP2)
            DIR=$APP2_DIR; FILE=$APP2_FILE;
            ;;
        *)
            printf "KABLAMO!"
            ;;
    esac

    if [ -d $DIR ]; then
        ( cd $DIR && node $FILE );

        # get nothing after here on first iteration and script hangs at this point

    fi
done

1 个答案:

答案 0 :(得分:1)

由于脚本不退出,您需要继续而不等待它们。因此,您应该在后台运行&

(cd "$DIR" && node "$file" &)
相关问题