Created
March 28, 2017 13:11
-
-
Save mikey179/595f9ed8c95297d15ca67fd5fbca02fd to your computer and use it in GitHub Desktop.
How to retrieve the full path where a script resides
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -o nounset | |
set -o errexit | |
selfbase() { | |
local selfbase="" | |
if [ -f $0 -a ! -h $0 ]; then | |
selfbase="$(dirname $0)" | |
elif [ $(uname) = "Darwin" ]; then | |
selfbase="$(dirname $(readlink $0))" | |
else | |
selfbase="$(dirname $(readlink -f $0))" | |
fi | |
if [ $selfbase = "." ]; then | |
selfbase=$(pwd) | |
fi | |
echo $selfbase | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment