On Wed, 27 Feb 2008, Kathryn Hogg wrote:

> If you want to print just the directory that the script is located in do
>
> (cd $(dirname $0); pwd)

That assumes that the script is in "dirname $0" but what if the script is 
in /usr/local/bin and /usr/local/bin is in the path and the user typed 
this:

script.bash

Then "dirname $0" will fail, and that is why the original poster suggested 
use of "which".  Also, you need quotes around the $0.


> if you want the full path to the script then this will suffice
> echo $(cd $(dirname $0); pwd)/$(basename $0)

That has the same problem as above.

Mike