在shell脚本循环中运行Node JS文件

时间:2014-07-23 07:28:27

标签: javascript node.js shell loops unix

我的shellcript看起来像

for i in {1..5}
    do
        echo "Welcome $i times"
        exec node nodefile.js
done

并且nodefile.js看起来像

console.log 'running nodefile'

当我调用./shellscript.sh时,只会显示“Welcome x times”和“running nodefile”一次。

那里错过了什么?我有什么必须在nodefile或其他东西中返回吗?

2 个答案:

答案 0 :(得分:1)

试试这个

for i in {1..5}
do
   echo "Welcome $i times"
   node process.js
done

答案 1 :(得分:0)

作为替代方案,您可以尝试使用' sha-bang'方法

将它放在nodefile.js中:

#!/the/location/of/your/node
console.log("running nodefile");

然后通过执行以下操作使nodefile.js可执行:

chmod +x nodefile.js

现在你的shell脚本看起来像这样:

for i in {1..5}
do
   echo "Welcome $i times"
   /location/of/nodefile.js
done
相关问题