Last active
May 13, 2022 23:16
-
-
Save mattmc3/603142693549105eb6ca06b6e47b4f7f to your computer and use it in GitHub Desktop.
Bash: get current script directory (zsh too)
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
# source this file | |
# https://stackoverflow.com/questions/9901210/bash-source0-equivalent-in-zsh | |
__main() { | |
local this_script="${BASH_SOURCE[0]:-${(%):-%x}}" | |
local this_dir="$(cd $(dirname "$this_script") && pwd)" | |
echo $this_script | |
echo $this_dir | |
} | |
__main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment