Last active
November 18, 2021 09:10
-
-
Save veryeasily/679e457931c134fe87cb282036637b3e to your computer and use it in GitHub Desktop.
[Get dir of current script] Gets the directory of the currently running script without getting tricked by symlinks #Shell #Zsh #Bash
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/local/bin/zsh | |
# @description Gets the physical location of the current script in a way that | |
# doesn't get tricked by symlinks | |
# @see https://stackoverflow.com/questions/59895/how-can-i-get-the-source-directory-of-a-bash-script-from-within-the-script-itsel | |
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)" | |
# next works for sourced files | |
# @see https://unix.stackexchange.com/a/4673/37091 | |
SCRIPT_DIR="$(cd -- "$(dirname -- "$_")" &> /dev/null && pwd)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment