That's a portable sh solution, isn't it? Like, yes, it does work on FreeBSD, but it isn't exclusive
rundir=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)")Additionally (and the article doesn't solve this either), when invoked through $PATH, $0 will not be a full path but only the name of the command. In that case you want to start with "$(command -v "$0")" instead of just "$0".
printf '%s/%s\n' "$(pwd -P)" "$(basename "$0")"
It's just been in place, in so many places, so long it's become unquestionable. So yes the `pwd -P` in this case will suffice.This approach breaks if you run the script from a symlink.
Will be added in the upcoming revision: https://www.austingroupbugs.net/view.php?id=1457
20 years ago it was a "BSD thing", but it seems to be more wide-spread these days; even my Alpine busybox system has it. I'm sure there are some platforms without it, but there are also platforms without some POSIX tools – it's never a guarantee.