#!/bin/bash

declare -a parms
# Set up classpath
cp=".:$BAGS_HOME:$BAGS_HOME/bsh-2.0b4.jar"
cp=$(cygpath -wp $cp)

# Shift the arguments to eliminate the script name
for (( i=0; i<$#+1; i++ )) ; do
	arg=$i
	if [ $arg -gt 0 ] ; then
		index=$((i-1))
		parms[$index]=${!arg}
	fi
done

cd $BAGS_HOME

if [ "${parms[0]}" == "-c" ] ; then
	java -cp $cp bsh.Console  
else 
	# Cygpath the bsh script, if running in cygwin
	if [ "${parms[0]}" != "" ] ; then
		parms[0]=$(cygpath -w ${parms[0]})
	fi
	# Call the BeanShell interpreter with the bsh script and arguments
	java -cp $cp BagsLauncher ${parms[@]} 
fi
