Advertisement
rodrigopolo

realpath

Jul 20th, 2013
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.54 KB | None | 0 0
  1. real_path () {
  2.     TARGET_FILE=$1
  3.     cd `dirname $TARGET_FILE`
  4.     TARGET_FILE=`basename $TARGET_FILE`
  5.    
  6.     # Iterate down a (possible) chain of symlinks
  7.     while [ -L "$TARGET_FILE" ]
  8.     do
  9.         TARGET_FILE=`readlink $TARGET_FILE`
  10.         cd `dirname $TARGET_FILE`
  11.         TARGET_FILE=`basename $TARGET_FILE`
  12.     done
  13.    
  14.     # Compute the canonicalized name by finding the physical path
  15.     # for the directory we're in and appending the target file.
  16.     PHYS_DIR=`pwd -P`
  17.     RESULT=$PHYS_DIR/$TARGET_FILE
  18.     echo $RESULT
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement