Skip to content

Instantly share code, notes, and snippets.

@dmrub
Created April 23, 2018 16:14
Show Gist options
  • Save dmrub/68510da8c67f0551b4df2a5cf3e9b616 to your computer and use it in GitHub Desktop.
Save dmrub/68510da8c67f0551b4df2a5cf3e9b616 to your computer and use it in GitHub Desktop.
How to get directory path of a shell script in bash
THIS_DIR="$(dirname "$(readlink -f "$BASH_SOURCE")")"
THIS_DIR=$( (cd "$(dirname -- "$BASH_SOURCE")" && pwd -P) )
THIS_DIR=$(dirname "$( readlink -f "${BASH_SOURCE}" 2>/dev/null || \
python -c "import os,sys; print(os.path.realpath(sys.argv[1]))" "${BASH_SOURCE}" )")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment