Skip to content

Instantly share code, notes, and snippets.

@ke4roh
Created August 5, 2015 16:52
Show Gist options
  • Save ke4roh/10e19a205c4a5a07d280 to your computer and use it in GitHub Desktop.
Save ke4roh/10e19a205c4a5a07d280 to your computer and use it in GitHub Desktop.
Where is JAVA_HOME?
#!/bin/bash
function whereIsFile() {
pushd . > /dev/null
FILE_PATH=$1;
while([ -h "${FILE_PATH}" ]) do cd -P $(dirname "${FILE_PATH}"); FILE_PATH=$(readlink "${FILE_PATH}"); done
cd -P $(dirname "${FILE_PATH}") > /dev/null
echo $(pwd)
popd >/dev/null
}
JAVA_HOME=$(dirname $(dirname $(whereIsFile $(which java))))
echo $JAVA_HOME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment