Created
August 18, 2021 10:50
-
-
Save Voronenko/a6e8fdfb4ab80ffc8221abd40cd3553c to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
SOURCE="${BASH_SOURCE[0]}" | |
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink | |
TARGET="$(readlink "$SOURCE")" | |
if [[ $TARGET == /* ]]; then | |
echo "SOURCE '$SOURCE' is an absolute symlink to '$TARGET'" | |
SOURCE="$TARGET" | |
else | |
DIR="$( dirname "$SOURCE" )" | |
echo "SOURCE '$SOURCE' is a relative symlink to '$TARGET' (relative to '$DIR')" | |
SOURCE="$DIR/$TARGET" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located | |
fi | |
done | |
echo "SOURCE is '$SOURCE'" | |
RDIR="$( dirname "$SOURCE" )" | |
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" | |
if [ "$DIR" != "$RDIR" ]; then | |
echo "DIR '$RDIR' resolves to '$DIR'" | |
fi | |
echo "DIR is '$DIR'" |
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
#!/usr/bin/env bash | |
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" |
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
!/usr/bin/env bash | |
SOURCE="${BASH_SOURCE[0]}" | |
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink | |
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" | |
SOURCE="$(readlink "$SOURCE")" | |
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located | |
done | |
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment