一些脚本语言(如Python或Bash)使用#
进行注释。
#!/usr/bin/env python
print 'hello, world'
我可以运行这个脚本:
python script.py
或
./script.py
有没有可能让JavaScript支持shebang?
发布于 2012-05-22 13:36:34
是的,你可以简单地使用#!/usr/bin/env node
(或者不管你的JavaScript解释器的名字是什么,它在js
(蜘蛛猴)上也工作得很好)。
[me@hades:~]> cat > test.js
#!/usr/bin/env node
console.log('hi');
[me@hades:~]> chmod +x test.js
[me@hades:~]> ./test.js
hi
最有可能的情况是,两个解释器都会测试第一行是否以#!
开头,在这种情况下会跳过第一行。
https://stackoverflow.com/questions/10696222
复制相似问题