Skip to content

Instantly share code, notes, and snippets.

@skiold
Created August 13, 2013 12:06
Show Gist options
  • Save skiold/6220454 to your computer and use it in GitHub Desktop.
Save skiold/6220454 to your computer and use it in GitHub Desktop.
#
# Determines the absolute path to the running script. This is useful for
# needing to muck around in the running directory when the script has been
# called using a relative path
#
getScriptAbsolutePath() {
if [[ ${0:0:1} == '/' ]]; then
# If the script was called absolutely
absPath=${0}
else
# If the script was called relatively, strip the . off the front
script=`echo ${0} | sed 's/\.\?\(.*\)$/\1/'`
absPath="$(pwd)/${script}"
fi
# Strip the script filename off the end
absPath=`echo ${absPath} | sed 's/\(.*\/\).*\$/\1/'`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment