Ralf Wildenhues wrote: > So I guess we need to stick to host matching in the code,
Shame, but at least it makes my life slightly easier ;-) Still finishing it off and getting it tested, but while that's going, here's a preview of the path canonicalisation function as I've got it so far; let me know if I've done any major no-nos please! cheers, DaveK
pathcar="s,^/\([^/]*\).*$,\1," pathcdr="s,^/[^/]*,," removedotparts="s,/\(\.\(/\|$\)\)\+,/,g" collapseslashes="s,/\+,/,g" # func_normal_abspath path # Remove doubled-up and trailing slashes, "." path components, # and cancel out any ".." path components in PATH. # value returned in "$func_normal_abspath_result" func_normal_abspath () { # Start from root dir and reassemble the path. func_normal_abspath_result= func_normal_abspath_tpath="$1" case "$func_normal_abspath_tpath" in "") # Empty path, that just means $cwd. func_stripname '' '/' "`pwd`" func_normal_abspath_result="$func_stripname_result" return ;; /*) # Absolute path, do nothing. ;; *) # Relative path, prepend $cwd. func_normal_abspath_tpath="`pwd`/$func_normal_abspath_tpath" ;; esac # Cancel out all the simple stuff to save iterations. func_normal_abspath_tpath="`$ECHO "$func_normal_abspath_tpath" | $SED \ -e "$removedotparts" -e "$collapseslashes"`" # We want the path to end with a slash for ease of parsing, and # doubled-up slashes won't hurt us here, so just add one on. func_normal_abspath_tpath="$func_normal_abspath_tpath/" while :; do func_normal_abspath_tcomponent="`$ECHO "$func_normal_abspath_tpath" | $SED \ -e "$pathcar"`" func_normal_abspath_tpath="`$ECHO "$func_normal_abspath_tpath" | $SED \ -e "$pathcdr"`" # Figure out what to do with it case "$func_normal_abspath_tcomponent" in "") # Trailing empty path component, ignore it. ;; ..) # Parent dir; strip last assembled component from result. func_dirname "$func_normal_abspath_result" func_normal_abspath_result="$func_dirname_result" ;; *) # Actual path component, append it. func_normal_abspath_result="$func_normal_abspath_result/$func_normal_abspath_tcomponent" ;; esac # Processed it all yet? if test "$func_normal_abspath_tpath" = / ; then # If we ascended to the root using ".." the result may be empty now. if test -z "$func_normal_abspath_result" ; then func_normal_abspath_result=/ fi break fi done }