Home

Back

Contents

Next

Special Variables and Values

In addition to the scope modifiers: 'this', 'super', 'global', BeanShell supports a number of pre-defined system variables, "magic" values, and methods.

Special Values

Note:
The choice of "bsh" for the root system object name was somewhat unfortunate because it conflicts with the current package name for BeanShell (also bsh). This means that if you wish to work with BeanShell classes explicitly from BeanShell scripts (e.g. bsh.Interpreter) you must first import them, e.g.:
    import bsh.Interpreter;
    i=new Interpreter();

Special Members of 'this' type References

'this' type references have several "magic" members:

These magic references are primarily used by BeanShell commands.

Undefined Variables

You can test to see if a variable is defined using the special value void. For example:

if ( foobar == void )
    // undefined

You can return a variable to the undefined state using the unset() command:

a == void;  // true
a=5;
unset("a"); // note the quotes
a == void;  // true

Setting the Command Prompt

Users may set the command line prompt string for use in interactive mode by setting the value of the variable bsh.prompt or by defining the scripted method (or command) getBshPrompt().

If the command or method getBshPrompt() is defined it will be called to get a string to display as the user prompt. For example, one could define the following method to place the current working directory into their command prompt:

	getBshPrompt() { return bsh.cwd + " % "; }

The default getBshPrompt() command returns the value of the variable bsh.prompt if it is defined or the string "bsh % " if not. If the getBshPrompt() method or command does not exist, throws an exception, or does not return a String, a default prompt of "bsh % " will be used.


Home

Back

Contents

Next