Skip to content

Instantly share code, notes, and snippets.

@vifo
Created January 3, 2013 14:09
Show Gist options
  • Save vifo/4443720 to your computer and use it in GitHub Desktop.
Save vifo/4443720 to your computer and use it in GitHub Desktop.
Bash: Get directory current script is located in (with Bash 2 fallback)
#!/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