Created
December 15, 2011 19:46
-
-
Save ashee/1482537 to your computer and use it in GitHub Desktop.
resolve symlinks at arbitrary depth
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
# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path. | |
while [ -h "$SCRIPT" ] ; do | |
ls=`ls -ld "$SCRIPT"` | |
# Drop everything prior to -> | |
link=`expr "$ls" : '.*-> \(.*\)$'` | |
if expr "$link" : '/.*' > /dev/null; then | |
SCRIPT="$link" | |
else | |
SCRIPT=`dirname "$SCRIPT"`/"$link" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment