3 ms·
I'm curious: why the `printf '%s\n' "$(pwd -P)"` ? wouldn't just `pwd -P` achieve the same?
by HerrMonnezza 3y ago
I'm curious: why the `printf '%s\n' "$(pwd -P)"` ? wouldn't just `pwd -P` achieve the same?
- alganet 3y agoI'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.
- mhio 3y agoActually 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.