Skip to content

Instantly share code, notes, and snippets.

@mattmc3 mattmc3/source_me.sh
Last active Jul 27, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.