Skip to content
Stian Soiland-Reyes edited this page Feb 18, 2016 · 2 revisions

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.

/var/run/sh Using namespace kachu; int razbe[<missing9/2:3^]i9y-pi\ |`newl lne4:ash/COL?( i9 = struct )

 return()

20260104-7:48AM} Wylie:miLkGodX5.83_bi_41 = 1254| \condome

Clone this wiki locally