Last active
September 19, 2020 19:37
-
-
Save jamescookie/f33e445830694660c2a747f074592d1f to your computer and use it in GitHub Desktop.
To switch JAVA_HOME in the current YADR zsh shell on a mac put this file in .zsh.after
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
function setJavaHome | |
{ | |
javaVersions=($(/usr/libexec/java_home -V 2>&1 | grep x86 | awk -F ":" '{print $1}' | awk -F "," '{print $1}' | xargs echo -n)) | |
newJava="" | |
while [[ $newJava = "" ]]; do | |
echo "Select your Java version for this shell" | |
select newJava in ${javaVersions[@]}; do | |
if [[ $newJava = "" ]]; then | |
echo "Please enter a valid option." | |
else | |
export JAVA_HOME=$(/usr/libexec/java_home -v $newJava) | |
echo $(java -version) | |
fi | |
break | |
done | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should work in a bash profile too, but you might have to change line 3 to be:
read -a javaVersions <<<$(/usr/libexec/java_home -V 2>&1 | grep x86 | awk -F ":" '{print $1}' | awk -F "," '{print $1}' | xargs echo -n)