How to expand relative paths in shell script

Viewed 56267

I am writing a script to set environment variables on linux 2.6 using bash. So the script contains commands like:

export SRC_DIR=..
export LIBPATH=${SRC_DIR}/lib

the problem is that when i try to do echo $LIBPATH, it shows "../lib" as opposed to expanding the SRC_DIR to full path. I would really like the script to print something like /home/x/lib as opposed to ../lib.

UPDATE The script should evaluate SRC_DIR to be one directory upwards from the script's location and not the current directory from where the script is invoked

7 Answers

For keeping error code:

function getPwd() {
    $(cd $1; [[ $? -ne 0 ]] && exit 1 || echo echo $PWD;)
    return $?
}
Related