title: Node.js SyntaxError: Unexpected end of input
body: <p>I wrote a function in shell script:</p>
  
  <pre><code>function nodee() {
      node -e "console.log((function() { $@ })());"
  }
  export -f nodee
  </code></pre>
  
  <p>And calling it like this:</p>
  
  <pre><code>nodee "var a = 1, b = 2;" "return a + b;"
  </code></pre>
  
  <p>Then I got an error:</p>
  
  <pre><code>[eval]:1
  console.log((function() { var a = 1, b = 2;
  
  SyntaxError: Unexpected end of input
      at Object.&lt;anonymous&gt; ([eval]-wrapper:6:22)
      at Module._compile (module.js:456:26)
      at evalScript (node.js:532:25)
      at startup (node.js:80:7)
      at node.js:902:3
  </code></pre>
  
  <p>But this is OK:</p>
  
  <pre><code>nodee "var a = 1, b = 2; return a + b;"
  </code></pre>
  
  <p>Finally, I found declaring <code>nodee</code> like this can fix the issue:</p>
  
  <pre><code>function nodee() {
      node -e "console.log((function() { `echo $@` })());"
  }
  export -f nodee
  </code></pre>
  
  <p>But the following two lines printed the same result:</p>
  
  <pre><code>echo "console.log((function() { `echo $@` })());"
  echo "console.log((function() { $@ })());"
  </code></pre>
  
  <p>So, the question is what's the difference between these two lines?</p>
  
  <pre><code>node -e "console.log((function() { `echo $@` })());"
  node -e "console.log((function() { $@ })());"
  </code></pre>
  
  <p>Mac OS X: 10.9.2 &amp; Node.js: 0.10.26</p>
  
  <p>Thanks in advance!</p>