3 ms·
> You mean $(realpath --relative-to=DIR) and $(realpath)? For historical reasons, some old Debian-based distros (such as Ubuntu 14.04 LTS "Trusty Tahr") doesn'
by jwilk 8y ago
> You mean $(realpath --relative-to=DIR) and $(realpath)?
For historical reasons, some old Debian-based distros (such as Ubuntu 14.04 LTS "Trusty Tahr") doesn't ship with coreutils' realpath. Instead, they have separate, somewhat incompatible realpath package, which doesn't have --relative-to.
Also, beware that $() strips trailing newlines.
- LukeShu 8y agoGood mention! I knew that realpath is a relatively new addition to GNU coreutils, but I didn't realize that older Debians had an incompatible implementation of it. With a single $(realpath ...), chomping the trailing newline is fine, as realpath will insert a trailing newline after the filename; but definitely something to be aware of with other commands.
- jwilk 8y agoNewline in realpath (and many other commands) output is mostly for aesthetics. It doesn't help with taming $(), because $() strips all trailing newlines, including the ones that were actually part of the pathname. You would have have to resort to something as ugly as: f=$(realpath ... && printf 'x') f=${f%x}