I lose this snippet sometimes so I needed to jot it down.
export HERE="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"Read more: Reliable way for a Bash script to get the full 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. |
I lose this snippet sometimes so I needed to jot it down.
export HERE="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"Read more: Reliable way for a Bash script to get the full path to itself?