SHOW:
|
|
- or go back to the newest paste.
| 1 | # Prints out the relative path between to absolute paths. Trivial. | |
| 2 | # | |
| 3 | # Parameters: | |
| 4 | # $1 = first path | |
| 5 | # $2 = second path | |
| 6 | # | |
| 7 | # Output: the relative path between 1st and 2nd paths | |
| 8 | relpath() {
| |
| 9 | local pos="${1%%/}" ref="${2%%/}" down=''
| |
| 10 | ||
| 11 | while :; do | |
| 12 | test "$pos" = '/' && break | |
| 13 | case "$ref" in $pos/*) break;; esac | |
| 14 | down="../$down" | |
| 15 | pos=${pos%/*}
| |
| 16 | done | |
| 17 | ||
| 18 | echo "$down${ref##$pos/}"
| |
| 19 | } |