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
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 either
node foo.jsalso runs the script (assuming the interpreter is called
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.