Last active
December 16, 2015 22:20
-
-
Save agate/5506697 to your computer and use it in GitHub Desktop.
DIR is the real directory of this script
This file contains hidden or 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
SOURCE="${BASH_SOURCE[0]}" | |
# resolve $SOURCE until the file is no longer a symlink | |
while [ -h "$SOURCE" ]; do | |
TARGET="$(readlink "$SOURCE")" | |
if [[ $SOURCE == /* ]]; then | |
SOURCE="$TARGET" | |
else | |
DIR="$( dirname "$SOURCE" )" | |
# if $SOURCE was a relative symlink, we need to resolve it relative | |
# to the path where the symlink file was located | |
SOURCE="$DIR/$TARGET" | |
fi | |
done | |
RDIR="$( dirname "$SOURCE" )" | |
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment