title: How do you climb up the parent directory structure of a bash script?
body: <p>Is there a neater way of climbing up multiple directory levels from the location of a script.</p>
  
  <p>This is what I currently have.</p>
  
  <pre><code># get the full path of the script
  D=$(cd ${0%/*} &amp;&amp; echo $PWD/${0##*/})
  
  D=$(dirname $D)
  D=$(dirname $D)
  D=$(dirname $D)
  
  # second level parent directory of script
  echo $D
  </code></pre>
  
  <p>I would like a neat way of finding the nth level. Any ideas other than putting in a for loop?</p>