title: How-To get root directory of given path in bash?
body: <p>My script:</p>
  
  <pre><code>    #!/usr/bin/env bash
      PATH=/home/user/example/foo/bar
      mkdir -p /tmp/backup$PATH
  </code></pre>
  
  <p>And now I want to get first folder of "$PATH": /home/</p>
  
  <pre><code>    cd /tmp/backup
      rm -rf ./home/
      cd - &gt; /dev/null
  </code></pre>
  
  <p>How can I always detect the first folder like the example above? "dirname $PATH" just returns "/home/user/example/foo/".</p>
  
  <p>Thanks in advance! :)</p>