Created
August 22, 2016 03:23
-
-
Save bramblex/a1f617318b7930cafdfa95f6fe65a868 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function __realpath__(){ | |
local CURRENT_DIR=$(pwd) | |
local TARGET_FILE=$1 | |
if [[ -e "$1" ]] | |
then | |
: | |
else | |
echo "$0: $1:No such file or directory" | |
return 1 | |
fi | |
cd `dirname $TARGET_FILE` | |
TARGET_FILE=`basename $TARGET_FILE` | |
# Iterate down a (possible) chain of symlinks | |
while [ -L "$TARGET_FILE" ] | |
do | |
TARGET_FILE=`readlink $TARGET_FILE` | |
cd `dirname $TARGET_FILE` | |
TARGET_FILE=`basename $TARGET_FILE` | |
done | |
# Compute the canonicalized name by finding the physical path | |
# for the directory we're in and appending the target file. | |
local PHYS_DIR=`pwd -P` | |
local RESULT=$PHYS_DIR/$TARGET_FILE | |
echo $RESULT | |
cd ${CURRENT_DIR} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment