【发布时间】:2017-01-14 17:30:36
【问题描述】:
我有一个接受整数 arg 的 node.js 文件。
我正在尝试编写一个 bash 脚本来查找可用内核的数量并为每个可用内核启动 main.js。
对于 1 个核心,它应该调用:
node main.js 3000 &
对于 2 个核心:
node main.js 3000 &
node main.js 30001 &
等等……
这是我的 bash 脚本:
#!/bin/bash
numCores=`getconf _NPROCESSORS_ONLN`
i=0
j=3000
while [ $i < $numCores ]
do
j=$($j+$i)
node /myApp/main.js $j &
i=$($i+1)
done
当我尝试运行它时,我得到了这个错误:
bash launchnode.sh
launchnode.sh: line 5: 2: No such file or directory
main.js 和launchnode.sh 在同一个目录。
有什么帮助吗?
【问题讨论】:
-
shellcheck.net 会自动为您捕捉到这个(以及许多其他错误)。
-
j=$(($j+$i)) 算术括号加倍