getting pwd of script

how can i get the absolute path of whatever directory a script and/or command is in when it is run?

i want to know the directory. say for instance, if i were to run the "who" command, i want to know exaclty where the who command is located.

if a user ran a script, i want to know where there script is located.

can this be done in a script?

shell: bash
os: linux / sunos

You can use pwd in the script to get the absolute path.

pwd

If you are looking for getting the absolute path for already running script, then you can try which <script name>. If it is located somewhere in the predefined path, then you will be able to see it. But this may not work.

which <script name>

dynamic variable PWD contains current directory:

$PWD