Posted By

cruelfate on 01/07/11


Tagged

path Bash sh


Versions (?)

base


 / Published in: Bash
 

Determine absolute minimal absolute path of parent directory containing this script. (remove any ".." path segments). Works with rudimentary Bourne shell as well as bash.

  1. #! /bin/sh
  2.  
  3. # Get absolute minimal absolute path of parent directory containing
  4. # this script with ".." path segments removed
  5.  
  6. d=`dirname $0`/..
  7. d=`(cd "$d"; pwd)`
  8. echo parent: $d
  9.  
  10. d=`dirname $0`
  11. d=`(cd "$d"; pwd)`
  12. echo self: $d
  13.  
  14. # bash version
  15. # echo parent: $(cd "$(dirname $0)/.."; pwd)
  16. # echo self: $(cd "$(dirname $0)"; pwd)

Report this snippet  

You need to login to post a comment.