Unix Env Shebang
If you write and distribute shell scripts or any executable that starts with a shebang
you might run into path issues.
#!/usr/bin/node
But what happens if you installed node on a different path, like /usr/local/bin/? You can use env
:
#!/usr/bin/env node
If we check what man
has to say about env
:
env executes utility after modifying the environment as specified on the command line. The option name=value specifies an environmental variable, name, with a value of value. The option '-i' causes env to completely ignore the environment it inherits.
If no utility is specified, env prints out the names and values of the variables in the environment, with one name=value pair per line.
Basically, env
looks for the given argument- ie node- in the $PATH and will run that executable.