Bash Script for setting JAVA_HOME on Linux & OSX

jvmVer=<code>java -version 2&amp;gt;&amp;amp;1 | grep &amp;quot;java version&amp;quot; | awk '{print $3}' | tr -d \&amp;quot;</code>
rc=$?
if [ ! &quot;$rc&quot; == &quot;0&quot; ]; then
  echo &quot; &quot;
  echo &quot;ERROR: JDK does not appear to be installed.&quot;
  exit 3
fi</p>

<p>if [ &quot;x$JAVA_HOME&quot; == &quot;x&quot; ]; then
  osName=<code>uname</code>
  if [ &quot;$osName&quot; == &quot;Darwin&quot; ]; then
    JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
  else
    JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-amd64
  fi
fi