Mike Miller wrote:
> 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.
> 

Hm. Not on my system. When I run a script in /usr/local/bin by typing 
test.sh, `dirname "$0"` returns /usr/local/bin. The path is getting 
expanded before the script runs.

That seems to work when running sh, bash, or tcsh at the command line or 
in the script itself.

-Steve