jashkenas/coffee-script — Issue #1817: Making coffeescript executable w/ shebang line on Linux
Author: jhuttner
Created: 2011-11-03 04:03:06+00:00
State: open

The script below works when run with the "coffee" command, but when I try to execute it using a shebang line it doesn't work. Any idea what could be going on? Thanks, Jeremy.

// coffee works
01:~ jhuttner$ /usr/bin/env coffee
coffee>

// contents of my file
01:~ jhuttner$ cat test.coffee
console.log("Oh, hello");

// it runs!
01:~ jhuttner$ coffee test.coffee
Oh, hello

// erase the file - we'll rebuild it a bit differently
01:~ jhuttner$ cat /dev/null > test.coffee

// start by putting the CoffeeScript interpreter at the top
01:~ jhuttner$ echo "#/usr/bin/env coffee" >> test.coffee

// a blank line for readability
01:~ jhuttner$ echo "" >> test.coffee

// the console.log
01:~ jhuttner$ echo 'console.log("Oh, hello");' >> test.coffee

// looks good....
01:~ jhuttner$ cat test.coffee
#/usr/bin/env coffee

console.log("Oh, hello");

// run using the coffee command
01:~ jhuttner$ coffee test.coffee
Oh, hello

// make executable
01:~ jhuttner$ chmod +x test.coffee

// why doesn't this work?
01:~ jhuttner$ ./test.coffee
./test.coffee: line 3: syntax error near unexpected token `"Oh, hello"'
./test.coffee: line 3: `console.log("Oh, hello");'