Thursday, January 24, 2008

How-to get absolute path of currently executing script

I googled this:

On 2006-06-15, Seb wrote:
> Hello,

> In a script shell (sh, bash, ksh, csh etc), how to get the absolute path
> of the script file's enclosing directory ?

Usually, if you want this, you are doing something wrong, or trying
to solve the wrong problem.

In a POSIX shell (ksh, bash, most recent versions of sh):

progdir=${0%/*}

In a Bourne shell:

progdir=`dirname $0`


Csh is not recommended for scripting.