Skip to content

Instantly share code, notes, and snippets.

@biiont
Created January 26, 2016 10:34
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 biiont/c93ddac609602eeb99af to your computer and use it in GitHub Desktop.
Save biiont/c93ddac609602eeb99af to your computer and use it in GitHub Desktop.
Universal way to find out scripts BASEDIR. Can be used as base for sourcable 'profile' to alter current environment for particular use (e.g. cross-compiler environment).
if [ "${0#/*profile*}" != "${0}" ]
then
BASEDIR=$(dirname "$(readlink -f "$0")")
else
if [ $# -gt 0 -a "${1#/*profile*}" != "${1}" ]
then
BASEDIR=$(dirname "$(readlink -f "$1")")
else
echo 'NOTE: When sourcing this profile on some shells (e.g. Busybox) you need to profile file name twice.'
echo 'Usage: . path/to/profile path/to/profile'
echo
return
fi
fi
echo '${BASEDIR}: '$BASEDIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment