title: OS X cannot detach volume, hdiutil error
body: <p>I need to install Java from command line. This is what I am trying:</p>
  
  <pre><code>hdiutil attach javaforosx.dmg
  cd /Volumes/Java\ for\ OS\ X\ 2015-001/
  sudo installer -pkg JavaForOSX.pkg -target "/"
  sudo hdiutil detach hdiutil detach /Volumes/Java\ for\ OS\ X\ 2015-001/
  </code></pre>
  
  <p>It fails at the last step, with the error message:</p>
  
  <pre><code>hdiutil: couldn't unmount "disk2" - Resource busy
  </code></pre>
  
  <p>What more, if I now go to my desktop and manually try to eject the disk image that is showing up in regards to Java (right click -> Eject) it says I cannot eject it, the terminal is using it. I have to close the terminal and only then I am able to eject the disk.</p>
  
  <p>How do I do it correctly from command line?</p>