Skip to content

Instantly share code, notes, and snippets.

@floer32
Created December 7, 2020 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save floer32/3903e42c33acde3d5f1cecd8f6be4c90 to your computer and use it in GitHub Desktop.
Save floer32/3903e42c33acde3d5f1cecd8f6be4c90 to your computer and use it in GitHub Desktop.
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}/common.sh"
# ... 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