1# vim:et:ft=sh:sts=2:sw=2 2# 3# Library of shell functions. 4 5# Convert a relative path into it's absolute equivalent. 6# 7# This function will automatically prepend the current working directory if the 8# path is not already absolute. It then removes all parent references (../) to 9# reconstruct the proper absolute path. 10# 11# Args: 12# shlib_path_: string: relative path 13# Outputs: 14# string: absolute path 15shlib_relToAbsPath() 16{ 17 shlib_path_=$1 18 19 # prepend current directory to relative paths 20 echo "${shlib_path_}" |grep '^/' >/dev/null 2>&1 \ 21 || shlib_path_="`pwd`/${shlib_path_}" 22 23 # clean up the path. if all seds supported true regular expressions, then 24 # this is what it would be: 25 shlib_old_=${shlib_path_} 26 while true; do 27 shlib_new_=`echo "${shlib_old_}" |sed 's/[^/]*\/\.\.\/*//g;s/\/\.\//\//'` 28 [ "${shlib_old_}" = "${shlib_new_}" ] && break 29 shlib_old_=${shlib_new_} 30 done 31 echo "${shlib_new_}" 32 33 unset shlib_path_ shlib_old_ shlib_new_ 34} 35