Skip to content

Instantly share code, notes, and snippets.

@tlrobinson
Created March 30, 2009 13:28
Show Gist options
  • Save tlrobinson/87785 to your computer and use it in GitHub Desktop.
Save tlrobinson/87785 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