Last active
October 25, 2016 02:45
-
-
Save aaronsteers/244654661a4abbd488e95acb65d03e2e to your computer and use it in GitHub Desktop.
Bash: get location of active script
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
## This moves execution into the script's parent directory. | |
## See also: http://stackoverflow.com/questions/59895/can-a-bash-script-tell-which-directory-it-is-stored-in | |
ORIG_DIR=$(pwd) | |
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}") | |
SCRIPT_PARENT_DIR="$(dirname "$SCRIPT_DIR")" | |
cd $SCRIPT_DIR | |
## | |
## Do stuff... | |
## | |
cd $ORIG_DIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment