如何使JavaScript的支持井号(#!)? [英] How to make javascript support shebang(#!)?
本文介绍了如何使JavaScript的支持井号(#!)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一些脚本语言(如Python或bash)的使用#
征求意见。
Some scripting languages (such as Python or Bash) use #
for comments.
#!/usr/bin/env python
print 'hello, world'
我可以运行该脚本:
I can run the script:
python script.py
或者
./script.py
时有可能使JavaScript支持家当?
Is it possible to make JavaScript support shebang?
推荐答案
是的,你可以简单地使用#!的/ usr / bin中/ env的节点
(或任何名称你的JavaScript间preTER,它正常工作与 JS
(SpiderMonkey的),太)。
Yes, you can simply use #!/usr/bin/env node
(or whatever the name of your JavaScript interpreter is, it works fine with js
(spidermonkey), too).
[me@hades:~]> cat > test.js
#!/usr/bin/env node
console.log('hi');
[me@hades:~]> chmod +x test.js
[me@hades:~]> ./test.js
hi
如果第一行开头
最有可能两者间preters测试#!
在这种情况下,它被跳过。
Most likely both interpreters test if the first line begins with #!
and in this case it is skipped.
这篇关于如何使JavaScript的支持井号(#!)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文