$PWD vs `pwd`

Hi,

can anyone expalin the real importance of PWD as a variable.
However pwd command and $PWD is going to give the same result, then why do we have 2 different things.
Please give some example which illustrates the difference between both.

Thanks

Hi,
Both are same w.r.t functionality , This variable points to the current directory

But $PWD is an environmental variable which can be used to set to a particular session/shell /script

Working principles of environment variables

A few simple principles govern how environment variables BY INSTALLING, achieve their effect.

Local to process

Environment variables are local to the process in which they were set. That means if we open two terminal windows (Two different processes running shell) and change value of environment variable in one window, that change will not be seen by other window.

Inheritance
When a child process is created, it inherits all the environment variables and their values from the parent process. Usually, when a program calls another program, it first creates a child process by forking, then the child adjusts the environment as needed and lastly the child replaces itself with the program to be called. This procedure gives the calling program control over the environment of the called program.

Case sensitive
In Unix and Unix-like systems the names of environment variables are case sensitive.
Persistence
Environment variables persistence can be session-wide or system-wide.

thanks,
venkat

It is interesting that the Shell built in command "pwd" agrees with the Shell Environment Variable "$PWD" but there are circumstances where and external "pwd" command may disagree in some versions of unix.

ls -lad /usr/spool
lrwxr-xr-t   1 root       sys             10 Aug 16  2000 /usr/spool -> /var/spool

cd /usr/spool

pwd
/usr/spool

pwd -P
/var/spool

echo $PWD
/usr/spool

/usr/bin/pwd
/var/spool

Thanks Methyl!!
As a general rule , we can have:
a)pwd returns the current absolute path
b)Whereas $PWD returns the path including the symbolic links.
Correct me if i am incorrect.
Thanks

Your answers do not tie up with my test results.
You are usually not using a unix system. Why not try it on your system and see what happens.

Sure Methyl.There's no difference in my ubuntu.Both returns same result.
May i know in which OS you tested?

pandeeswaran@ubuntu:~/lnktraining$ ls -lad /home/pandeeswaran/lnktraining
lrwxrwxrwx 1 pandeeswaran pandeeswaran 27 2012-01-17 23:06 /home/pandeeswaran/lnktraining -> /home/pandeeswaran/training
pandeeswaran@ubuntu:~/lnktraining$ pwd
/home/pandeeswaran/lnktraining
pandeeswaran@ubuntu:~/lnktraining$ echo $PWD
/home/pandeeswaran/lnktraining
pandeeswaran@ubuntu:~/lnktraining$ cd ..
pandeeswaran@ubuntu:~$ cd training
pandeeswaran@ubuntu:~/training$ pwd
/home/pandeeswaran/training
pandeeswaran@ubuntu:~/training$ echo $PWD
/home/pandeeswaran/training
pandeeswaran@ubuntu:~/training$ 

Look closer at my post. The differences I saw were with these commands:

pwd -P
/usr/bin/pwd

I'd be interested to know if Ubuntu behaves the same way as unix. My test was with HP-UX but I have seen the effect on other unixes.

just for peace:
aix 4.2.1:

ge2:/home/vbe $ cd /u
ge2:/u $ pwd
/u
ge2:/u $ /usr/bin/pwd
/home
ge2:/u $ pwd -P
/home
ge2:/u $ oslevel
4.2.1.0

AIX 6:

n12:/u $ pwd
/u
n12:/u $ pwd -P
/home
n12:/u $ oslevel
6.1.0.0
n12:/u $ /usr/bin/pwd
/home
n12:/u $ echo $PWD
/u 

sparc solaris 10:

lo4:/export/home/vbe $ cd /bin
lo4:/bin $ pwd
/bin
lo4:/bin $ /usr/bin/pwd
/usr/bin
lo4:/bin $ pwd -P
/usr/bin
lo4:/bin $ uname -r
5.10

Redhat 5 entreprise:

rh5:/usr/tmp $ pwd
/usr/tmp
rh5:/usr/tmp $ pwd -P
/var/tmp
rh5:/usr/tmp $ echo $PWD
/usr/tmp
rh5:/usr/tmp $ /usr/bin/pwd
-ksh: /usr/bin/pwd: not found [No such file or directory]
rh5:/usr/tmp $ /bin/pwd
/var/tmp
rh5:/usr/tmp $  
rh5:/usr/tmp $ uname -r
2.6.18-238.9.1.el5

Yes Methyl!!

pwd -P

makes the difference.

pandeeswaran@ubuntu:~/lnktraining$ pwd
/home/pandeeswaran/lnktraining
pandeeswaran@ubuntu:~/lnktraining$ pwd -P
/home/pandeeswaran/training

In my system , i am not able to find /usr/bin/pwd command.

pandeeswaran@ubuntu:~/lnktraining$ /usr/bin/pwd
bash: /usr/bin/pwd: No such file or directory

Thanks.

Now i get the differences.
I guess in most of the linux systems,

/usr/bin/pwd

command is not usually available.

Thank you very much!

You will find /usr/bin/ on all UNIx system that a SVR4 compliant for in the SVR4 file system layout, the directory /usr deifinition is: Sharable operating system commands, libraries and documentation.
To not let people panic at the time when migrating to the new structure, links were provided for compatibility. HP had even what they called "transition links" ( HP-UX 9 to HP-UX10...)
Linux are not SVR4 compliant...