Finding path of a running script

Hi,
I just want to know any code by which i can get the path of the script which i am running. This is required to store the output in the same directory from where the script is running. pwd fails if I give absolute path of script from some other directory.
Thanks in advance
Puneet

try ps -ef|grep scriptname... or something like this..

 /usr/ucb/ps -wwaxe processid | tr " " "\n" | grep PWD

should work or:

/usr/ucb/ps -wwaxe 54458 | sed 's/.* \(PWD=[^ ]*\) .*/\1/'

You can use realpath to retrieve the canonicalized absolute pathname of your shell script.
With this information you can easily figure out the current working directory.