Created
January 3, 2013 14:09
-
-
Save vifo/4443720 to your computer and use it in GitHub Desktop.
Bash: Get directory current script is located in (with Bash 2 fallback)
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
#!/usr/bin/env bash | |
SCRIPT_PATH="${BASH_SOURCE[0]}" # for Bash > 3.0 | |
[ -z "${SCRIPT_PATH}" ] && SCRIPT_PATH=$(readlink -f "$0") # for Bash 2 | |
SCRIPT_DIR=$(cd $(dirname "${SCRIPT_PATH}") && pwd) | |
echo "Script path: ${SCRIPT_PATH}" | |
echo "Script directory: ${SCRIPT_DIR}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment