title: bash: extracting last two dirs for a pathname
body: <p>I seem to have failed at something pretty simple, in bash. I have a string variable that holds the full path to a directory. I'd like to assign the last <strong>two</strong> directories in it to another string. For example, if I have:</p>
  
  <pre><code>DIRNAME = /a/b/c/d/e
  </code></pre>
  
  <p>I'd like:</p>
  
  <pre><code>DIRNAME2 = d/e
  </code></pre>
  
  <p>I'm sure there's a simple bash construct or <code>sed</code> command that will do it, but it's escaping me.  I'd sort of like a generalized version of <code>basename</code> or <code>dirname</code> that doesn't just return the extreme parts of a name.</p>
  
  <p>Thanks!
  Dave</p>