Last active
May 30, 2019 15:00
-
-
Save ryenus/5db80fbb2835ec2d177300c5a04ae348 to your computer and use it in GitHub Desktop.
show, list or set java version for current shell, mac only
This file contains hidden or 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
# show, list or set java version for current shell | |
# usage: jv; jv -l; or jv 8 | |
jv() { | |
local d v="$1" | |
if [ $# -ge 1 ]; then | |
[ -z "${v#-[lLV]}" ] && { /usr/libexec/java_home -V; return; } | |
[ -z "${v##-*}" ] && { /usr/libexec/java_home "$@"; return; } | |
[ ${#v} -eq 1 -a -z "${v#[0-8]}" ] && v="1.$v" | |
[ -n "$v" ] && d=$(/usr/libexec/java_home -v "$v") && \ | |
export JAVA_HOME="$d" | |
fi | |
[ -n "$JAVA_HOME" ] && echo "JAVA_HOME: $JAVA_HOME" | |
java -version | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment