bourne shell absolute path

By Hal Canary, 2010-03-31 10:20:12 (link)
#uncategorized

#!/bin/sh
abspath () {
    D7636=`/usr/bin/dirname "$1"`;
    D7636=`(cd "$D7636"; pwd -P)`;
    B7636=`/usr/bin/basename "$1"`;
    echo "${D7636}/${B7636}";
}
PATH=$1
echo "path = \"${PATH}\""
ABSPATH=`abspath "$PATH"`
echo "absolute path = \"${ABSPATH}\""

UPDATE: I just realised that readlink -f "$FILE" will do the trick.


UPDATE 2: Even better, since it is concise and follows the POSIX standard:

#!/bin/sh
abspath () {
    echo "$(cd "$(dirname "$1")" ; pwd;)/$(basename "$1")"
}

(back)