My Ubuntu-friend told me to testrun a Beanshell script by doing:

bsh #filename#

and when I told him that I don't know what bsh is nor have it he told me:

sudo apt-get install bsh

Being on a Mac I instead ran:

sudo port install beanshell

But still no bsh command available. A listing of the package content revealed a jar file named:


but when I try to run that with my script file a complete Window manager written in Java starts up (and does not run the script file btw). Now, clearly I am doing something wrong, I am sure there must be a way of running beanshell scripts on a mac terminal although it does seem more natural for the linux users. What am I doing wrong and what should I do to run that script?

  • If you want to know how to do it: java -cp /opt/local/share/java/bsh.jar bsh.Interpreter (apparently I am not allowed to answer) :(
    – jonalv
    Sep 12 '11 at 16:01

First check that bsh.jar is on your CLASSPATH. If it is not, add it by running:

export CLASSPATH=$CLASSPATH:/opt/local/share/java/bsh.jar

Then run it like this:

java bsh.Interpreter filename

See the manual for more information.

  • yea even nicer. I got totally side tracked by the instructions to just run bsh filename...
    – jonalv
    Sep 12 '11 at 16:15
  • 1
    You could write a shell script called bsh consisting of java -cp /opt/local/share/java/bsh.jar bsh.Interpreter "$@".
    – Kevin Reid
    Dec 1 '11 at 3:45

For Mac OS X, someone has created a Beanshell installer.



Its even easier if you just drop the bsh.jar into your JAVA_HOME/jre/lib/ext directory. Then you only need to call it with: java bsh.Interpreter filename.bsh without needing to mess with the classpath.

  • I wouldn't recommend putting jars in JAVA_HOME/jre, because if you upgrade the JRE, you have to remember to copy yours jars into the new JRE. (also see stackoverflow.com/questions/2068961/…)
    – dogbane
    Dec 1 '11 at 8:25
  • In the case of beanshell, its just one jar, so its no problem. I usually have my shell script copy the jar into place if its missing and so i dont forget.
    – djangofan
    Dec 2 '11 at 0:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.