[Unix] spaces in realpath

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[Unix] spaces in realpath

Bert Freudenberg

Hi Ian,

the realpath() function in the "squeak" script does not like spaces in the path. Here is one that doesn't mind (only else-case differs):

realpath () {
    path="$1"
    while test -L "${path}"; do
            dir=`dirname "${path}"`
            dir=`cd "${dir}" && pwd -P`
            path=`basename "${path}"`
            path=`ls -l "${dir}/${path}" | sed 's,.* -> ,,'`
            path="${dir}/${path}"
    done
    if test -d "${path}"; then
            (cd "${path}" && pwd -P)
    else
            dir=`dirname "${path}"`
            file=`basename "${path}"`
            (cd "${dir}" && echo "`pwd -P`/${file}")
    fi
}

- Bert -