Node.js is very popular these days and I've been writing some scripts on it. Unfortunately, compatibility is a problem. Officially, the Node.js interpreter is supposed to be called node, but Debian and Ubuntu ship an executable called nodejs instead.
I want portable scripts that Node.js can work with in as many situations as possible. Assuming the filename is foo.js, I really want the script to run in two ways:
./foo.jsruns the script if eithernodeornodejsis in$PATH.node foo.jsalso runs the script (assuming the interpreter is callednode)
Note: The answers by xavierm02 and myself are two variations of a polyglot script. I'm still interested in a pure shebang solution, if such exists.
nodefor your script, or having a kind of make script that modifies the shebang. – Feb 20 '13 at 12:17alphacentauriand such. If there's an executable callednodejs, you can be 99% sure it's Node.js. Why not support bothnodejsandnode? – StackExchange saddens dancek Feb 20 '13 at 13:28