Last active
July 4, 2018 17:15
-
-
Save cboddy/bf045ad337281a55a876fd06feddbc39 to your computer and use it in GitHub Desktop.
A utility for compiling and running a single file Java program (for scripting)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# compile a java source file and run it | |
# | |
# two options: | |
# 1. Add to interactive environment | |
# | |
# > source jscript.sh. | |
# (or do the above in ~/.bashrc) | |
# to make the function jscript available eg. | |
# > jscript HelloWorld.java | |
# | |
# 2. run this script as an executable eg. | |
# > ./jscript.sh HelloWorld.java | |
# | |
function jscript { | |
javac $1 && java $(echo $1 | sed 's/.java//') | |
rm -f $(echo $1 | sed 's/.java/.class/') | |
} | |
if [[ $_ = $0 ]] | |
then | |
jscript $1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment