Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Clarify that no groovy arguments can be used with the shebang

...

If you install a binary distribution of Groovy then you can run the Groovy Swing console by typing this on the command line.

Code Block
none
none

groovyConsole

For a command line interactive shell type

Code Block
none
none

groovysh

To see how to add things to the classpath see below.

...

There is a helper class called GroovyShell which has a main(String[]) method for running any Groovy script. You can run any groovy script as follows

Code Block
none
none

java groovy.lang.GroovyShell foo/MyScript.groovy [arguments]

...

There are shell scripts called 'groovy' or 'groovy.bat' depending on your platform which is part of the Groovy runtime.
Once the runtime is installed you can just run groovy like any other script...

Code Block
none
none

groovy foo/MyScript.groovy [arguments]

...

The following is a sample script, which you should copy and save as helloWorld.groovy.

Code Block
none
none

#!/usr/bin/env groovy
println("Hello world")
for (a in this.args) {
  println("Argument: " + a)
}

Then to run the script from the command line, just make sure the script is executable then you can call it.

Code Block
none
none

chmod +x helloWorld
./helloWorld

Anchor
classpath
classpath

Note that you will not be able to provided any arguments to groovy when running with the shebang(#!) on Linux because the arguments are treated as part of the name of the command to run. Mac OS X will interpret additional arguments correctly.

Adding things to the classpath

...