Skip to content

Instantly share code, notes, and snippets.

@mattmc3
Last active May 13, 2022 23:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattmc3/603142693549105eb6ca06b6e47b4f7f to your computer and use it in GitHub Desktop.
Save mattmc3/603142693549105eb6ca06b6e47b4f7f to your computer and use it in GitHub Desktop.
Bash: get current script directory (zsh too)
# 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