title: How to get base path from path in shell script?
body: <p>I would need to find a way in Bash (Linux shell in general) to get a <strong>base path from a given path</strong>. There are a few rules:</p>
  
  <ul>
  <li>in the given path there will be one directory called <code>ABC</code>.</li>
  <li>the directory <code>ABC</code> contains a subdirectory which I don't know the name of. Below I call it <code>XYZ</code>.</li>
  </ul>
  
  <p>Given this path</p>
  
  <pre><code>/some/absolute/path/foo/ABC/XYZ/bar/path/here
  </code></pre>
  
  <p>the result should be:</p>
  
  <pre><code>/some/absolute/path/foo/ABC/XYZ
  </code></pre>
  
  <p>The problem I'm having is due to <code>XYZ</code>, because I don't know it, but need to keep it in the returned path.</p>
  
  <p>Without the unknown <code>XYZ</code> I could do this:</p>
  
  <pre><code>pwd | sed -e 's/ABC.*/ABC/'
  </code></pre>
  
  <p>Does anyone have a solution how I can solve this in Bash? Thanks!</p>