Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
bash/zsh script - how to get absolute path to itself
export HERE="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
# example usage - source a script in same directory. but using absolute path,
# ... which you'd do so that a script can be called from wherever. (not dependent on working directory ($PWD))
. "${HERE}/"
# ... or of course you could export DIRNAME or whatever you want.
# In scripts I just find "$HERE/node_modules", "$HERE/src" etc to be pretty readable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment