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.

vector
  • 7,334
  • 8
  • 52
  • 80

2 Answers2

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).
Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • ... just tried playing with this, still no joy, added more details to question. – vector Nov 28 '12 at 00:48
  • @vector I don't understand your shebang. – Dave Newton Nov 28 '12 at 00:55
  • my groovy installation sits in /home/me/groovy instead of /usr/bin/env – vector Nov 28 '12 at 01:00
  • @vector Then it's still wrong, IMO. Search for "unix shebang" to see what it actually does. – Dave Newton Nov 28 '12 at 01: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 http://stackoverflow.com/questions/5479731/shebang-and-groovy). So, letting `env` execute groovy is the workaround for that. – Brian Henry Nov 28 '12 at 02:41
  • @vector To clarify Dave's idea: you supply that stuff as listed, then you can run `PostBuilder.groovy` on the command line - no preceding `groovy` required, which is what I think you're doing. – Brian Henry Nov 28 '12 at 02:53
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.

Brian Henry
  • 3,161
  • 1
  • 16
  • 17