title: How to determine and use the actual java path in a Linux shell script
body: <p>In a bash shell script on Ubuntu/Mint, I need to create some symlinks in the /jre/lib/ext/ directory under the java installation directory.</p>
  
  <p>For example, if openjdk6 is the default java, /usr/bin/java points to:</p>
  
  <pre><code>/usr/lib/jvm/java-6-openjdk/jre/bin/java
  </code></pre>
  
  <p>I can find this in my script with:</p>
  
  <pre><code>MYJAVAPATH=readlink -f `which java`
  </code></pre>
  
  <p>The path I would need in my shell script would be based on part of that path, plus the path fragment above:</p>
  
  <pre><code>/usr/lib/jvm/java-6-openjdk/jre/lib/ext/
  </code></pre>
  
  <p>Can anyone tell me to to derive the path immediately above in a bash shell script? Thanks.</p>