如何 #!工作以及如何使其适用于CoffeeScript?

Thi*_*ilo 6 macos shell coffeescript

我可以像Perl或shell脚本一样制作可执行的CoffeeScript文件吗?

像添加一样的东西

#!coffee
Run Code Online (Sandbox Code Playgroud)

在上面?(我试过了,我得到的只是'糟糕的翻译')

我在OS X上,如果这有所作为.

Eri*_*lin 7

您可以使用:

#!/usr/bin/env coffee

console.log 'hello coffeescript!'
Run Code Online (Sandbox Code Playgroud)

只要确保你也使文件可执行:

chmod +x myfile.coffee
Run Code Online (Sandbox Code Playgroud)

然后你可以运行它:

myfile.coffee
Run Code Online (Sandbox Code Playgroud)