Hacker News new | ask | show | jobs
by HerrMonnezza 935 days ago
I'm curious: why the `printf '%s\n' "$(pwd -P)"` ? wouldn't just `pwd -P` achieve the same?
2 comments

Actually nothing. The format seems to have come from a similar line that builds the script path..

    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.
I've been using just `V="$(cd -- "$(dirname -- "$0")"; pwd)"` for ages, everything quoted, several OSs, never had an issue with the output that required me to format it again.

This approach breaks if you run the script from a symlink.