Advertisement
Guest User

Untitled

a guest
Mar 12th, 2016
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement