Created
January 26, 2016 10:34
-
-
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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