0

I've put together a utility script in groovy and would like to run it in any directory as needed without having to specify full path to it. As in $> groovy myScript.groovy

I've added the path to it's parent directory to PATH in .profile, sourced it, but keep gettig 'command not found' error. Any idea where to look for the problem, conceptually speaking?

Where things are:

First line of my PostBuilder.groovy script: #!/usr/bin/env groovy`

PATH in .profile: export PATH=$PATH:/home/me/work/web/MyProject/public_html

The error I'm getting now trying to execute the script in my home directory:

Caught: java.io.FileNotFoundException: /home/me/PostBuilder.groovy (/home/me/PostBuilder.groovy)

FYI, my Groovy/Grails set up works just fine so I'm thinking installation of groovy itself is ok.

2 Answers 2

2

It's more likely what you really want is to:

  1. Add the path the script is in to your PATH environment variable, and
  2. Make it executable via chmod u+x, and
  3. Shebang it with #!/usr/bin/env groovy (or your equivalent).
6
  • ... just tried playing with this, still no joy, added more details to question.
    – vector
    Nov 28, 2012 at 0:48
  • @vector I don't understand your shebang. Nov 28, 2012 at 0:55
  • my groovy installation sits in /home/me/groovy instead of /usr/bin/env
    – vector
    Nov 28, 2012 at 1:00
  • @vector Then it's still wrong, IMO. Search for "unix shebang" to see what it actually does. Nov 28, 2012 at 1:07
  • @vector You can't supply groovy directly as the target of the shebang, as it turns out. Has to be a binary, and groovy is a shell script (see comments in stackoverflow.com/questions/5479731/shebang-and-groovy). So, letting env execute groovy is the workaround for that. Nov 28, 2012 at 2:41
1

Add the path to groovy/bin to your PATH. Then you can run groovy, but you'd still need to be in the directory of your .groovy script, or supply full path, to execute.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.