jastrachan | 7 Apr 22:00 2005

Re: how to access 'Variables' variable

On 7 Apr 2005, at 15:31, Gayathri Karthik wrote:
> Hello All,
> Everytime i execute something ( i mean add a variable declaration and
> initialize it for example) on the groovy console, i see 'Variables'
> getting updated to reflect the current global variables. That looks
> cool. Is there anyways i can access it in my code? It looks like a
> Map.Can I directly bind functions to global scope by adding the entry
> to the 'Variables' map?

If you're embedding Groovy in your code you can access this from the 
GroovyShell. See the getContext() method


which returns a Binding


Inside a shell script you can access the variable 'shell'.
e.g. to display the variables

for (e in shell.context.variables) {
     println "variable $e.key has value $e.value"