I wrote a function in shell script:
function nodee() {
node -e "console.log((function() { $@ })());"
}
export -f nodee
And calling it like this:
nodee "var a = 1, b = 2;" "return a + b;"
Then I got an error:
[eval]:1
console.log((function() { var a = 1, b = 2;
SyntaxError: Unexpected end of input
at Object.<anonymous> ([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
But this is OK:
nodee "var a = 1, b = 2; return a + b;"
Finally, I found declaring nodee like this can fix the issue:
function nodee() {
node -e "console.log((function() { `echo $@` })());"
}
export -f nodee
But the following two lines printed the same result:
echo "console.log((function() { `echo $@` })());"
echo "console.log((function() { $@ })());"
So, the question is what's the difference between these two lines?
node -e "console.log((function() { `echo $@` })());"
node -e "console.log((function() { $@ })());"
Mac OS X: 10.9.2 & Node.js: 0.10.26
Thanks in advance!