kev*_*kev 21 javascript bash shebang node.js
一些脚本语言(如Python或Bash)#用于注释.
#!/usr/bin/env python
print 'hello, world'
Run Code Online (Sandbox Code Playgroud)
我可以运行脚本:
python script.py
Run Code Online (Sandbox Code Playgroud)
要么
./script.py
Run Code Online (Sandbox Code Playgroud)
是否有可能使JavaScript支持shebang?
Thi*_*ter 36
是的,您可以简单地使用#!/usr/bin/env node(或者您的JavaScript解释器的名称,它也适用于js(spidermonkey)).
[me@hades:~]> cat > test.js
#!/usr/bin/env node
console.log('hi');
[me@hades:~]> chmod +x test.js
[me@hades:~]> ./test.js
hi
Run Code Online (Sandbox Code Playgroud)
很可能两个解释器都会测试第一行是否开头,#!在这种情况下它会被跳过.
| 归档时间: |
|
| 查看次数: |
7975 次 |
| 最近记录: |