title: Get a bash script to run node.js
body: <p>I have a node.js file that accepts an integer arg.</p>
  
  <p>I'm trying to write a bash script that looks for number of available cores and launches main.js for each available core.</p>
  
  <p>For 1 core it should call:</p>
  
  <pre><code>node main.js 3000 &amp;
  </code></pre>
  
  <p>For 2 cores:</p>
  
  <pre><code>node main.js 3000 &amp;
  node main.js 30001 &amp;
  </code></pre>
  
  <p>And so on...</p>
  
  <p>This is my bash script:</p>
  
  <pre><code>#!/bin/bash
  numCores=`getconf _NPROCESSORS_ONLN`
  i=0
  j=3000
  while [ $i &lt; $numCores ]
  do
      j=$($j+$i)
      node /myApp/main.js $j &amp;
      i=$($i+1)
  done
  </code></pre>
  
  <p>When I try to run it, I get this error:</p>
  
  <pre><code>bash launchnode.sh
  launchnode.sh: line 5: 2: No such file or directory
  </code></pre>
  
  <p>main.js and launchnode.sh are in the same directory.</p>
  
  <p>Any help?</p>