Skip to content

Instantly share code, notes, and snippets.

@aaronsteers
Last active October 25, 2016 02:45
Show Gist options
  • Save aaronsteers/244654661a4abbd488e95acb65d03e2e to your computer and use it in GitHub Desktop.
Save aaronsteers/244654661a4abbd488e95acb65d03e2e to your computer and use it in GitHub Desktop.
Bash: get location of active script
## 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