编译本目录下得一个java文件的脚本

  1. #!/bin/bash
  2. #

  3. function usage()
  4. {
  5. echo "parameter error "
  6. echo "$0 file"
  7. echo "file is the java source code you want to compile and run"
  8. exit 1;
  9. }

  10. postfix=`echo "$1" | awk -F . '{print $2}'`


  11. # if the parameter is not enough
  12. # or not in the form of "*.java"
  13. # then show the usage
  14. if [ $# != 1 -o "$postfix" != "java" ]
  15. then
  16. usage
  17. fi

  18. cur_dir=`pwd`
  19. file_name=$1
  20. a=${file_name%.*}
  21. javac $file_name -d $cur_dir

  22. if [ "$?"=="0" ]
  23. then
  24. java $a
  25. else
  26. echo "compile failed!"
  27. fi
09-28 04:00