How to get absolute path name of shell script on MacOS?

readlink -f does not exist on MacOS. The only working solution for Mac OS I managed to find on the net goes like this: if [[ $(echo $0 | awk '/^\//') == $0 ]]; then ABSPATH=$(dirname $0) else ...