2

I've installed coffeescript and shellJS, using NPM. I have a test script, shtest.coffee:

#!/usr/local/bin/coffee
require 'shelljs/global'
echo 'hello'
exit 1

Running the script with coffee works fine:

$ coffee shtest.coffee
hello

Or with shjs:

$ shjs shtest.coffee
hello

But not directly:

$ chmod u+x shtest.coffee
$ ./shtest.coffee
./shtest.coffee: line 2: require: command not found
hello

Changing the shebang to point to /usr/local/bin/js doesn't help.

It looks like the script is being run as a bash script. What am I doing wrong? OS X Snow Leopard.

3
  • Where is your 'coffee' installed? Is there, for example, a 'coffee' file in /usr/local/bin? Commented Oct 2, 2013 at 16:45
  • Well, yes, of course. which coffee -> /usr/local/bin/coffee Commented Oct 3, 2013 at 1:30
  • Does #!/usr/local/bin/coffee work with an other simple coffee script? Commented Oct 3, 2013 at 1:35

1 Answer 1

5

Try using

#!/usr/bin/env coffee

as your shebang line. That works for me at least, though I'm not sure why exactly (apart from it having to do with the ENV somehow)

Sign up to request clarification or add additional context in comments.

2 Comments

Hmm, it possibly has to do with the apparent requirement that the interpreter pointed to must not itself be a script ( en.wikipedia.org/wiki/Shebang_(Unix) ). coffee is a script that begins #!/usr/bin/env node. Maybe.
@SteveBennett Didn't know that, but it does seem like a reasonable explanation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.