是否可以在不知道要执行的程序的路径的情况下指定 shebang 行?
也许不指定路径
#!node
或指定几个选项
#!/usr/local/bin/node
#!/usr/bin/node
跨平台解决方案的加分项(各种风格的 linux、BSD、OSX 等...)
最佳答案
/usr/bin/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.
所以在以下几行:
#!/usr/bin/env node
将是跨平台的和“正确的道路”。
关于未知路径的shell脚本shebang,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11889892/