Message-ID: <845051543.1435.1425084237764.JavaMail.email@example.com> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_1434_1403382992.1425084237763" ------=_Part_1434_1403382992.1425084237763 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
The Groovy Shell, aka.
groovysh is a command-line applicati=
on which allows easy access to evaluate Groovy expressions, define classes =
and run simple experiments.
gocommand to execute buffer.
The shell supports several options to control verbosity, ANSI coloring a= nd other features.
When a complete expression is found, it is compiled and evaluated. The r= esult of the evaluation is stored into the _ variable.
Multi-line/complex expressions (like closure or class definitions) may b= e defined over several lines. When the shell detects that it has a complete= expression it will compile and evaluate it.
Shell variables are all untyped (ie. no
def or other type information.
This will set a shell variable:
But, this will evaluate a local variable and will not b= e saved to the shell's environment:
Functions can be defined in the shell, and will be saved for later use.<= /p>
Defining a function is easy:
And then using it is as one might expect:=20 =20 =20
The shell has a number of different commands, which provide rich access = to the shell's environment.
Commands all have a name and a shortcut (which is some=
:h). Commands may also have some predefined system =
aliases. Users may also create their own aliases.
Display the list of commands (and aliases) or the help text for specific= command.
While in the interactive shell, you can ask for help for any command to =
get more details about its syntax or function. Here is an example of what h=
appens when you ask for help for the
Exit the shell.
This is the only way to exit the shell. Well, you can s=
CTRL-C, but the shell will complain about an abnormal shu=
tdown of the JVM.
Add a custom import which will be included for all shell evaluations.
This command can be given at any time to add new imports.
Display the contents of the current buffer.
This only displays the buffer of an incomplete expression. Once the expr= ession is complete, the buffer is rest. The prompt will update to show the = size of the current buffer as well.
Clears the current buffer,= resetting the prompt counter to 000. Ca= n be used to recover from compilation er= rors.
Show variables, classes or preferences or imports.
:show preference= s
Opens the GUI object browser to inspect a variable or the result of the = last evaluation.
Purges objects from the shell.
:purge preferen= ces
Edit the current buffer in an external editor.
Edit requires the
EDITOR environment variable to be set, or=
editor preference to be configured.
Load one or more files (or urls) into the buffer.
Saves the buffer's contents to a file.
Record the current session to a file.
Display, manage and recall edit-line history.
Create an alias.
Set or list preferences.
Opens a browser window displaying the doc for the argument.
Some of aspects of
groovysh behaviors can be customized by =
setting preferences. Preferences are set using the
Set the shell's verbosity level. Expected to be one of:
If this preference is set to an invalid value, then the previous setting= will be used, or if there is none, then the preference is removed and the = default is used.
Show the last result after an execution.
Sanitize (trim-down/filter) stack traces.
Configures the editor used by the
Default is the value of the system environment variable
To list the current set preferences (and their values):=20 =20
This script, if it exists, is loaded when the shell starts up.
This script, if it exists, is loaded when the shell enters interactive m= ode.
Edit-line history is stored in this file.
Please report any problems you run into. Please be =
sure to mark the JIRA issue with the
On Windows, JLine (which is used for the fancy shell input/history/co=
mpletion fluff), uses a tiny DLL file to trick the evil Windows faux-shell (
M) into providing Java with unbuffered input. In some rare cases, th=
is might fail to load or initialize.
One solution is to disable the frills and use the unsupported terminal i=
nstance. You can do that on the command-line using the
--terminal flag and set it to one of:
Some people have issues when running groovysh with cygwin. If you have t= roubles, the following may help: