-2

From coreutils' manual about ln

-r --relative

Make symbolic links relative to the link location.

Example:

ln -srv /a/file /tmp
’/tmp/file’ -> ’../a/file’

Relative symbolic links are generated based on their canonicalized containing directory, and canonicalized targets. I.e., all symbolic links in these file names will be resolved. See Section 18.5 [realpath invocation], page 161, which gives greater control over relative fi le name generation, as demonstrated in the following example:

ln--relative() {
test "$1" = --no-symlinks && { nosym=$1; shift; }
target="$1";
test -d "$2" && link="$2/." || link="$2"
rtarget="$(realpath $nosym -m "$target" \
--relative-to "$(dirname "$link")")"
ln -s -v "$rtarget" "$link"
}

Is the purpose of the example ln--relative() to implement the same asln -sr? Thanks.

Tim
  • 101,790

1 Answers1

1

No, the shell-function ln--remote gives you a means to create relative symbolic links where the target path will not have symbolic-links resolved, which by default ln -r would do.

And it shows you how you could write a function, that uses more of the parameters of readpath just in case you do need even more control over the output filename.