Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #!/bin/bash
  2. readonly GITHUB_PATH=~/Documents/GitHub
  3.  
  4. function compileRun () {
  5. r () {
  6. if [ $1 -eq 0 ]
  7. then #compiled successfully
  8. java $2
  9. return 0
  10. else #compile failed
  11. echo "Couldn't compile, so we will not run \"java $2\"" >&2
  12. return 1
  13. fi
  14. }
  15. if test -f "${1}.java"; then #this means that it finds the file you're trying to compile in the present directory
  16. javac "${1}.java"
  17. r $? $1
  18. return $?
  19. else #couldn't find your file, so it needs to search
  20. a=$(find ${GITHUB_PATH} -name ${1}.java)
  21. b=$(echo $a | sed -e 's/[^\/]*$//g')
  22. cd "$b"
  23. javac "$a"
  24. r $? $1
  25. return $?
  26. fi
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement