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.

1 comment:

Anonymous said...

Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Notebook, I hope you enjoy. The address is http://notebooks-brasil.blogspot.com. A hug.