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

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

Something like adding

#!coffee 

on top? (I tried this, and all I get is a "bad interpreter")

I'm on OS X if that matters.

+6
source share
3 answers

You can use:

 #!/usr/bin/env coffee console.log 'hello coffeescript!' 

Just make sure you also make the executable:

 chmod +x myfile.coffee 

Then you can run it with:

 myfile.coffee 
+7
source

Have you tried the absolute path? A “bad interpreter" usually means that there is a fraudulent new line at the end, for example. you need to run dos2unix on it.

+1
source

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

or you can cheat using env

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

Looks like you already made sure you created the script executable if you get this error

+1
source

Source: https://habr.com/ru/post/894783/


All Articles