Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does #! work and how can I make it work for CoffeeScript?

Can I make a CoffeeScript file executable just like a Perl or shell script?

Something like adding

#!coffee

on top? (I tried that, and all I get is 'bad interpreter')

I'm on OS X if that makes a difference.

like image 501
Thilo Avatar asked Aug 11 '11 02:08

Thilo


3 Answers

You can use:

#!/usr/bin/env coffee

console.log 'hello coffeescript!'

Just make sure you also make the file executable:

chmod +x myfile.coffee

Then you can run it with:

myfile.coffee
like image 183
Eric Wendelin Avatar answered Oct 22 '22 02:10

Eric Wendelin


Have you tried the absolute path? "Bad interpreter" usually means there's a rogue newline at the end, e.g. you need to run dos2unix on it.

like image 43
Aaron D. Marasco Avatar answered Oct 22 '22 03:10

Aaron D. Marasco


You need an absolute path (on linux at least, OSX may be different)

or you can cheat by using env

#!/usr/bin/env coffee
# **Your script here**

It looks like you've already made sure you've made the script executable if you are getting that error

like image 39
tobyodavies Avatar answered Oct 22 '22 04:10

tobyodavies