Home

Back

Contents

Next

Executable scripts under Unix

You can use BeanShell for writing scripts as you would any other shell under many Unixs:

#!/usr/java/bin/java bsh.Interpreter 

print("foo");

However some flavors of Unix are more picky about what they will allow as a shell program. For those you can use the following hack to make your BeanShell scripts executable.

#!/bin/sh
# The following hack allows java to reside anywhere in the PATH.
//bin/true; exec java bsh.Interpreter "$0" "$@"

print("foo");

The above trick presumes that /bin/true exists on your system and that //bin is the same as /bin. The // causes BeanShell to ignore the line.

The above has been tested on Solaris. It does not seem to work under Cygwin.

OSX

For OSX the path is a bit different:

#!/Library/Java/home/bin/java bsh.Interpreter

print("foo");

On OSX /usr/bin/java is itself a shell script, which unfortunately won't work out-of-the-box.

Home

Back

Contents

Next