#!/usr/bin/env node 求解释亲们
发布于 9 年前 作者 suntopo 12101 次浏览 最后一次编辑是 8 年前 来自 问答

http://blog.csdn.net/tsangyang/article/details/8507056 其中有一句话不理解 因为 Node 安装可能会在 /usr/local/bin/ 而不是 /usr/bin/ 就需要 env 命令在前边

3 回复

env is a shell command for Unix and Unix-like operating systems. It is used to either print a list of environment variables or run another utility in an altered environment without having to modify the currently existing environment.

env, Wikipedia

明明是

/usr/bin/env js

env may also be used in the hashbang line of a script to allow the interpreter to be looked up via the PATH. For example, here is the code of a very simple Python script:

#!/usr/bin/env python2 print "Hello World." In this example, /usr/bin/env is the full path of the env command. The environment is not altered.

Note that it is possible to specify the interpreter without using env, by giving the full path of the python interpreter. A problem with that approach is that on different computer systems, the exact path may be different. By instead using env as in the example, the interpreter is searched for and located at the time the script is run. This makes the script more portable, but also increases the risk that the wrong interpreter is selected because it searches for a match in every directory on the executable search path. It also suffers from the same problem in that the path to the env binary may also be different on a per-machine basis.

回到顶部