Skip to content

Instantly share code, notes, and snippets.

@kpietru
Last active April 21, 2016 10:47
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 kpietru/2ca118cf2182e63bfa1375f527e26381 to your computer and use it in GitHub Desktop.
Save kpietru/2ca118cf2182e63bfa1375f527e26381 to your computer and use it in GitHub Desktop.
# Magic variables: __FILE__, __DIR__, __BASE__, __ROOT__
bashSource="${BASH_SOURCE[0]}"
while [ -h "${bashSource}" ]; do
if [[ "${bashSource}" == /* ]]; then
bashSource="$(readlink "${bashSource}")"
else
bashSource="$(dirname "${bashSource}")/$(readlink "${bashSource}")"
fi
done
__FILE__="${bashSource}"
__DIR__="$(cd -P "$(dirname "${__FILE__}")" && pwd)"
__BASE__="$(basename "${__FILE__}" .sh)"
__ROOT__="$(dirname "${__DIR__}")"
# Or
# Magic variables: __FILE__, __DIR__, __BASE__, __ROOT__
eval 'p=`readlink -f "${BASH_SOURCE[0]}"`;__FILE__="$p";__DIR__=`dirname "$p"`;__BASE__=`basename "$p".sh`;__ROOT__=`dirname "$__DIR__"`'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment