是否可以在不知道要执行的程序路径的情况下指定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 - Shell脚本shebang未知路径,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11889892/