Normalized and relative file pathsSometimes one needs to convert a file path into a form that is relative to an arbitrary base (not necessarily the current directory). That's what the functionrelpath does. Example:
path=a/b/c base=../x/y pwd # Output: /usr/joe relpath $base $path # Output: ../../joe/a/b/c relpath ../x/./y ./a/../a/b/c .. and . components. Also, file names with
embedded blanks (a common pitfall in shell programming) should be handled correctly.
The function may be called with one or two parameters:
|