Skip to content

Instantly share code, notes, and snippets.

View alanmur's full-sized avatar
💭
Code guru

Al Murray alanmur

💭
Code guru
View GitHub Profile
@alanmur
alanmur / dirname.md
Last active December 9, 2021 13:38
Getting the absolute script path of a shell script

Getting the absolute script path of a shell script

# Directory script was called from
PWD="$(pwd)"
# Path part of the command line (caveats http://mywiki.wooledge.org/BashFAQ/028)
DIRNAME=$(dirname -- "$0")
# Calculate absolute directory name
if [[ $DIRNAME =~ ^/ ]] ; then
 ABSDIRNAME="$(cd "${DIRNAME}"; pwd)"