title: Bash shell script: How to set JAVA_HOME environment variable
body: <p>Using openSUSE, I downloaded the Oracle rpms for jdk1.6.0_24  and I want to set the java home environment variable to  /usr/java/jdk1.6.0_24  but  the /etc/alternatives system is unable to automatically detect this installed JDK.  Update-alternatives , or whatever just doesn't find the jdk.</p>
  
  <p>So, I want to detect the JAVA home manually in a BASH script.  </p>
  
  <p>If I run this command:  sudo find /usr -name 'jdk1.6*'  , I get this result:</p>
  
  <pre><code>/usr/java/jdk1.6.0_24
  </code></pre>
  
  <p>How do pipe that result into a environment variable?   I want to do something like</p>
  
  <pre><code>#!/bin/bash
  read in JAVA_HOME var from a file
  if file doesnt exist
    sudo find /usr -name 'jdk1.6*' 
    prompt user for which jdk is correct
    set that choice to a variable 
    add the JDK to alternatives if it is missing
    save variable to a file and dont prompt next time
    set the alternatives java choice
  fi
  echo $JAVA_HOME
  </code></pre>