Skip to content

Instantly share code, notes, and snippets.

@asaaki
Created August 28, 2015 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asaaki/9af7bc2451d3dcb03c8d to your computer and use it in GitHub Desktop.
Save asaaki/9af7bc2451d3dcb03c8d to your computer and use it in GitHub Desktop.
Absolute final directory path of origin script
#!/bin/sh
# Shamelessly stolen from:
# https://github.com/michaeldfallen/git-radar/blob/master/git-radar#L7-L13
if [[ "$OSTYPE" == *darwin* ]]; then
READLINK_CMD='greadlink'
else
READLINK_CMD='readlink'
fi
script_location="$(cd "$(dirname "$([ -L "$0" ] && $READLINK_CMD -f "$0" || echo "$0")")"; pwd)"
echo "I was called from: $0"
echo "Final directory of the origin script is at: $script_location"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment