title: best way to find top-level directory for path in bash
body: <p>I need a command that will return the top level base directory for a specified path in bash. </p>
  
  <p>I have an approach that works, but seems ugly:</p>
  
  <pre><code>echo "/go/src/github.myco.com/viper-ace/psn-router" | cut -d "/" -f 2 | xargs printf "/%s"
  </code></pre>
  
  <p>It seems there is a better way, however all the alternatives I've seen seem worse.</p>
  
  <p>Thanks for any suggestions!</p>