Skip to content

Instantly share code, notes, and snippets.

@adragomir
Forked from tlrobinson/gist:87785
Last active August 29, 2015 14:18
Show Gist options
  • Save adragomir/ce0e23c6c62fd02dcc1f to your computer and use it in GitHub Desktop.
Save adragomir/ce0e23c6c62fd02dcc1f to your computer and use it in GitHub Desktop.
#!/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