- #!/bin/bash
- #
- function usage()
- {
- echo "parameter error "
- echo "$0 file"
- echo "file is the java source code you want to compile and run"
- exit 1;
- }
- postfix=`echo "$1" | awk -F . '{print $2}'`
- # if the parameter is not enough
- # or not in the form of "*.java"
- # then show the usage
- if [ $# != 1 -o "$postfix" != "java" ]
- then
- usage
- fi
- cur_dir=`pwd`
- file_name=$1
- a=${file_name%.*}
- javac $file_name -d $cur_dir
- if [ "$?"=="0" ]
- then
- java $a
- else
- echo "compile failed!"
- fi