Posted By

deepsoul on 08/07/09


Tagged

path absolute canonical


Versions (?)

Canonical absolute path


 / Published in: Bash
 

The following shell function returns the canonicalised abolute path of a file. It resolves symbolic links, /./ and /../ as applicable. This was adapted from various sources. Related snippets on snipplr are Find absolute path of Bash script and Get current script name and absolute paths.

  1. function canonpath ()
  2. {
  3. echo $(cd $(dirname $1); pwd -P)/$(basename $1)
  4. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: sschuldenzucker on March 1, 2012

Quotes!

echo "$(cd $(dirname "$1"); pwd -P)/$(basename "$1")"

You need to login to post a comment.