0

From coreutils about realpath

--relative-to=file Print the resolved file names relative to the specified file. Note this option honors the -m and -e options pertaining to file existence.

--relative-base=base This option is valid when used with --relative-to, and will restrict the output of --relative-to so that relative names are output, only when files are descendants of base. Otherwise output the absolute file name. If --relative-to was not specified, then the descendants of base are printed relative to base. If --relative-to is specified, then that directory must be a descendant of base for this option to have an effect. Note: this option honors the -m and -e options pertaining to file existence. For example:

realpath --relative-to=/usr /tmp /usr/bin
⇒ ../tmp
⇒ bin
realpath --relative-base=/usr /tmp /usr/bin
⇒ /tmp
⇒ bin
  1. Does "This option is valid when used with --relative-to" mean that --relative-base can't work without --relative-to specified?

    Then why does it also say later that "If --relative-to was not specified, then the descendants of base are printed relative to base", which implies that --relative-base can work without --relative-to specified?

  2. "If --relative-to was not specified, then the descendants of base are printed relative to base. If --relative-to is specified, then that directory must be a descendant of base for this option to have an effect."

    What are the differences between the two cases with and without --relative-to specified?

    In the quote, are the two cases the same, in the sense that only the descendants of base are printed relative to base, while others are printed as absolute pathnames?

Thanks.

1

The developers found this obscure and changed it more than four years ago:

There is no need to recompute for every path being visited whether the base is a prefix of the relative location.

Most of the time, if someone wants to filter which paths are relative while leaving all others absolute, they also want to to the filtering based on the same --relative-to directory. Make this easier to specify.

But the documentation for --relative-base and --relative-to appears to have not been reworded to clarify that if --relative-to was not specified, then it defaults to the value given for --relative-base.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.