Created
March 30, 2009 13:28
-
-
Save tlrobinson/87785 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
#!/bin/bash | |
# get the absolute path of the executable | |
SELF_PATH=$(cd -P -- "$(dirname -- "$0")" && pwd -P) && SELF_PATH=$SELF_PATH/$(basename -- "$0") | |
# resolve symlinks | |
while [ -h $SELF_PATH ]; do | |
# 1) cd to directory of the symlink | |
# 2) cd to the directory of where the symlink points | |
# 3) get the pwd | |
# 4) append the basename | |
DIR=$(dirname -- "$SELF_PATH") | |
SYM=$(readlink $SELF_PATH) | |
SELF_PATH=$(cd $DIR && cd $(dirname -- "$SYM") && pwd)/$(basename -- "$SYM") | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment