By Alvin Alexander. Last updated: April 28, 2019
Here's a Bourne Shell (sh) script I use to run a Java anti-spam program I wrote. The program I'm running isn't important, but what is worth sharing about this shell script is how I dynamically build the Java CLASSPATH by including all of the jar files in the lib directory.
Other parts of the shell script (showing a shell script for loop) may be worth sharing as well, but I think that building the Java classpath dynamically in the shell script is probably the most important part.
With that being said, here's the shell script:
#!/bin/sh
export JAVA_HOME=/usr/local/java
PATH=/usr/local/java/bin:${PATH}
cd /home/ala/DevDaily/Musubi
#---------------------------------#
# dynamically build the classpath #
#---------------------------------#
THE_CLASSPATH=
for i in `ls ./lib/*.jar`
do
THE_CLASSPATH=${THE_CLASSPATH}:${i}
done
#---------------------------#
# run the anti-spam program #
#---------------------------#
java -cp ".:${THE_CLASSPATH}" \
EmailAgentController \
lib/mail.properties \
lib/userMail.properties \
message.uid.cache \
| tee -a SPAM.mbox
I guess the Linux tee command and the line continuation stuff is good too, if you've never seen that. Bourne Shell programming — heck, programming on a Unix system — is pretty cool.

