Skip to content

Instantly share code, notes, and snippets.

@bramblex
Created August 22, 2016 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bramblex/a1f617318b7930cafdfa95f6fe65a868 to your computer and use it in GitHub Desktop.
Save bramblex/a1f617318b7930cafdfa95f6fe65a868 to your computer and use it in GitHub Desktop.
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