Question

I have a shell script to run node with some arguments like so:

#!/usr/bin/env node --harmony_proxies
...

This works fine under OS X but in Ubuntu it errors with:

/usr/bin/env: node --harmony_proxies: No such file or directory

Node is definitely installed and on the PATH since if I remove the --harmony_proxies flag it works fine. Is there some different way of passing arguments when using env in Ubuntu?

Was it helpful?

Solution

On Linux, the entire string following the interpreter name is passed as a single argument to the interpreter, and this string can include white space. [1] Thus, command line arguments are not split, and env command is trying to execute node --harmony_proxies file, which obviously could not be found. See here and here for more details.

Here is an alternative solution for you:

#!/bin/sh
exec node --harmony_proxies "$@"

Hope it helps. Good luck!

OTHER TIPS

If the node command is installed in a fixed location, you can use it directly:

#!/usr/bin/node --harmony_proxies

But if you can't assume that node is installed in a particular location, go with one of the other answers.

If you don't want to modify the source, a wrapper alias might be the right solution.

Example from my .bashrc:

alias how2='/usr/bin/env node --no-deprecation "$(which how2)"'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top