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
I like this:
#!/usr/bin/env bash function realpath() { local _X="$PWD" local _LNK=$1 cd "$(dirname "$_LNK")" if [ -h "$_LNK" ]; then _LNK="$(readlink "$_LNK")" cd "$(dirname "$_LNK")" fi echo "$PWD/$(basename "$_LNK")" cd "$_X" }