Mental Jetsam

By Peter Finch

Archive for June 5th, 2008

Determine a shell scripts home directory.

Posted by pcfinch on June 5, 2008

The following bit of shell script is useful in determining the home directory of the script being run. When a script is executed from the command line normally it’s home directory is the directory that the script was execute from not the directory the script lives in. This can make it difficult to load other
resources that may be in the scripts home directory or relative to it.

DIRNAME=`dirname "$0"`
SCRIPTDIR=`(cd $DIRNAME && pwd)`

Posted in Programming | 2 Comments »