path relative-to for path
Command Type
built-in
Signature
> path relative-to {flags} (path)
Flags
--walk-up: Allow..components when the argument path is not a parent of the input path.
Parameters
path: Path to express the input path relative to.
Input/output types:
| input | output |
|---|---|
| string | string |
| list<string> | list<string> |
Examples
Find a relative path from two absolute paths.
> '/home/viking' | path relative-to '/home'
vikingFind a relative path from absolute paths in list.
> [ /home/viking, /home/spam ] | path relative-to '/home'
╭───┬────────╮
│ 0 │ viking │
│ 1 │ spam │
╰───┴────────╯Find a relative path from two relative paths.
> 'eggs/bacon/sausage/spam' | path relative-to 'eggs/bacon/sausage'
spamWalk up with .. when the argument path is not a parent of the input path.
> '/home/viking' | path relative-to '/home/spam/eggs' --walk-up
../../vikingNotes
Can be used only when the input and the argument paths are either both absolute or both relative. Without --walk-up, the argument path needs to be a parent of the input path.
The paths are compared as text, without touching the filesystem. With --walk-up, each .. in the result stands for the textual parent of the argument path, so if the argument path goes through a symbolic link, the result may point somewhere else than the textual path suggests. When --walk-up has to add .., names are compared with exact case, even on Windows and macOS.