Created
May 25, 2010 18:44
-
-
Save jschnare/413510 to your computer and use it in GitHub Desktop.
This file contains 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
# from: http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-in | |
# credits: 3bcdnlklvc04a, e-satis | |
# Works for all versions,including when called via multple depth soft link, | |
# when script called by command "source" aka . (dot) operator. when arg $0 is | |
# modified from caller. "./script" "/full/path/to/script" | |
# "/some/path/../../another/path/script" "./some/folder/script" SCRIPT_PATH is | |
# given in full path, no matter how it is called. Just make sure you locate | |
# this at start of the script. | |
# This comment and code Copyleft, selectable license under the GPL2.0 or later | |
# or CC-SA 3.0 (CreativeCommons Share Alike) or # later. (c) 2008. All rights | |
# reserved. No warranty of any kind. You have been warned. | |
# http://www.gnu.org/licenses/gpl-2.0.txt | |
# http://creativecommons.org/licenses/by-sa/3.0/ | |
SCRIPT_PATH="${BASH_SOURCE[0]}"; | |
if([ -h "${SCRIPT_PATH}" ]) then | |
while([ -h "${SCRIPT_PATH}" ]) do SCRIPT_PATH=`readlink "${SCRIPT_PATH}"`; done | |
fi | |
pushd . > /dev/null | |
cd `dirname ${SCRIPT_PATH}` > /dev/null | |
SCRIPT_PATH=`pwd`; | |
popd > /dev/null | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment