I am trying to obtain the absolute path to the currently running script on OS X.
I saw many replies going for readlink -f $0. However since OS X\'s
readlink -f $0
realpath for Mac OS X
realpath() { path=`eval echo "$1"` folder=$(dirname "$path") echo $(cd "$folder"; pwd)/$(basename "$path"); }
Example with related path:
realpath "../scripts/test.sh"
Example with home folder
realpath "~/Test/../Test/scripts/test.sh"