Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Groovy Shell

The Groovy Shell, aka. groovysh is a command-line application which allows easy access to evaluate Groovy expressions, define classes and run simple experiments.


This page pertains to the new groovysh which at the moment needs to be explicitly enabled by setting the NEWSHELL environment variable to any value (unset or empty will invoke the previous groovysh implementation).

NEWSHELL=true ./bin/groovysh

Command-line Options and Arguments

The shell supports several options to control verbosity, ANSI coloring and other features.

./bin/groovysh --help
usage: groovysh [options] [...]
  -C, --color[=FLAG]         Enable or disable use of ANSI colors
  -D, --define=NAME=VALUE    Define a system property
  -T, --terminal=TYPE        Specify the terminal TYPE to use
  -V, --version              Display the version
  -d, --debug                Enable debug output
  -h, --help                 Display this help message
  -q, --quiet                Suppress superfluous output
  -v, --verbose              Enable verbose output

In addition to options, commands or expressions can be given on the command-line which will invoke the shell in non-interactive mode. The commands or expressions will be evaluated and the shell will exit.

./bin/groovysh 'show preferences'
No preferences are set
./bin/groovysh ' { k, v -> println("$k = $v") }' = Java(TM) 2 Runtime Environment, Standard Edition
sun.boot.library.path = /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Libraries
java.vm.version = 1.5.0_07-87
awt.nativeDoubleBuffering = true
gopherProxySet = false


Some of aspects of groovysh behaviors can be customized by setting preferences. Preferences are set using the set command or the \= shortcut.

Recognized Preferences


Set the shell's verbosity level. Expected to be one of:

  • INFO

Default is INFO.

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.

Default is true.


Sanitize (trim-down/filter) stack traces.

Default is true.

Setting a Preference

set verbosity DEBUG

Listing Set Preferences

show preferences

Clearing Preferences (ie. Resetting to Defaults)

purge preferences

Screen Shots

Wishlist for the Swing Console (aka. groovyConsole)

  • basic syntax highlighting in source code
  • line numbers (be able to turn on / off)
  • be able to specify some .jar files that will be included into the classpath
  • enable standard-de-facto ctrl+z for undo and ctrl+y for redo
  • tabs
  • code formatting

Debug features:

  • step-by-step execution of statements
  • improve variables insight for clarity


  • No labels