Created
August 4, 2017 11:18
-
-
Save 9nix00/283ed38cfd100cfc83ef22be2eb6a0e7 to your computer and use it in GitHub Desktop.
greadlink
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
| #!/bin/sh | |
| TARGET_FILE=$1 | |
| if [ $TARGET_FILE == "-f" ];then | |
| TARGET_FILE=$2 | |
| 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. | |
| PHYS_DIR=`pwd -P` | |
| RESULT=$PHYS_DIR/$TARGET_FILE | |
| echo $RESULT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment