<section>
<name filename="standalonemode">Modes of Operation</name>

There are currently five basic modes of operation for running BeanShell:

<ul>
<li>Standalone scripts</li>
<li>Embedded in your application</li>
<li>Remote server mode</li>
<li>Servlet mode</li>
<li>Applet mode</li>
</ul>

We'll outline these in this and the coming sections.
<p/>

BeanShell is also integrated into a number of other tools and development
environments including the Emacs JDE and the NetBeans/Forte for Java IDE.
Please see the web site for articles and information about using BeanShell
within these third party tools.

<h2>Standalone</h2>

<img src="scriptmode.gif"/>
<br CLEAR="ALL"/>

You can use BeanShell to run scripts from the command line or enter
statements interactively by starting the bsh.Interpreter class.
(See "Quickstart" for instructions on adding BeanShell to your classpath.)
<p/>

<example>
 java bsh.Interpreter [ filename ] [ arg ] [ ... ]  // Run a script file
</example>

There are a few options which can be passed to the Interpreter using Java
system properties:

<ul>
<li><strong>outfile</strong> - Send all output to the specified file by 
redirecting System.out and System.err</li>

<li><strong>debug</strong> - Turn on debugging output by setting to
true.  <em>Note: this mode
is very verbose and unstructured.  It is not intended for general
use.</em></li>

<li><strong>trace</strong> - Setting trace to true turns on method tracing.  
This mode prints each line before it is executed.  <em>Note that this currently 
prints only top level lines as they are parsed and executed by the 
interpreter.  Trace skips over method executions (including bsh commands) 
etc.  This mode is incomplete.  It should be considered experimental.</em>
</li>
</ul>

<h2>Remote</h2>

The bsh.Remote launcher is the equivalent of bsh.Interpreter, but runs
the specified file in a remote BeanShell engine.  The remote engine may
be a servlet mode BeanShell engine (BshServlet) or a native server mode 
remote BeanShell instance (embedded interpreter).
<p/>

bsh.Remote accepts a URL and filename as arguments:

<example>
// servlet mode URL
java bsh.Remote http://localhost/bshservlet/eval test1.bsh

// remote server mode URL
java bsh.Remote bsh://localhost:1234/ test1.bsh
</example>

An HTTP URL may be specified that points to an instance of BshServlet
(See "Servlet Mode" for details).  Or a native "bsh:" URL may be specified,
pointing to an instance of the BeanShell interpreter running in remote
server mode.

<em>
At the time of this writing bsh: style URLs for accessing native remote
server mode instances are not implemented.
</em>
<p/>

In either case, bsh.Remote sends the script to the remote engine for
evaluation.  If Remote can parse the retun value of the script as an integer 
it will return the value as the exit status to the command line.  

<h2>Interactive Use</h2>

One of the most popular uses for BeanShell is, of course, as a "shell" for
interactive experimentation and debugging.  BeanShell can be run in a GUI 
desktop mode that offers a number conveniences like command line history,
cut &amp; paste, and tools for interactive use such as a simple classbrowser.  
We'll talk about the GUI in "The BeanShell Desktop" later.  

<tip>
The BeanShell GUI is comprised mostly of a set of BeanShell scripts supplied 
in the JAR file and launched by the BeanShell desktop() command.
</tip>

However BeanShell can also be run interactively in plain text on the command 
line.  

<example>
 java bsh.Interpreter   // Run interactively on the command line
</example>

This is useful for quick "one liners"; however it does not offer 
creature comforts such as command line history and editing.  We should note
that some shells, such as the Windows environment, do command line history 
and editing automatically - providing these features for BeanShell.
<p/>

<tip>
You can exit from an interactive shell by typing Control-D.
</tip>

The return statement is ignored in interactive mode (it does not exit the 
shell).
<p/>

<h2>The .bshrc Init File</h2>

When run interactively, BeanShell looks for a startup file called ".bshrc"
in the user's home directory.  If the file is found it is sourced into the
interactive shell.  You can use this to perform setup for your interactive
use.  For example, to add additional default imports or to toggle on the
show() command if you prefer that.
<p/>

The location of the .bshrc file is determined by the Java system property
"user.home", which has different locations under different operating systems.
The following table lists common locations:

<h3>.bshrc File Location:</h3>

<table border="1" cellpadding="5">
<tr><td>Unix</td><td>$HOME/.bshrc</td></tr>

<tr><td>
Win95/98 single user
</td><td>
C:\Windows\.bshrc 
</td></tr>

<tr><td>
Win98 Multiuser
</td><td>
C:\Windows\Profiles\&lt;username&gt;\.bshrc
</td></tr>

<tr><td>
NT/2K
</td><td> 
C:\Winnt\Profiles\&lt;username&gt;\.bshrc
</td></tr>

</table>

</section>

