What is the difference between the `pwd` builtin and the $ PWD builtin?

Here is a case. I have a directory call: -% / Home / MyName /

I made a soft link in this directory:% cd / home / myname /% ln -s / home / others /.

Now I connect to others / from / home / myname / Here is the interesting part.

When I made a built-in command pwdfor unix, I get the path name ORIGINAL: -% / Home / other /

But when I return the $ PWD environment variable, I get the path name:% / Home / MyName / others /

Why is this so?

+3
source share
2 answers
/ var # ls -l
lrwxrwxrwx 1 root root 10 Aug 22 13:21 mail -> spool / mail
drwxr-xr-x 2 root root 4096 Jul 1 20:58 opt
drwxr-xr-x 22 root root 4096 Dec 5 17:38 run
drwxr-xr-x 12 root root 4096 Aug 22 13:21 spool
drwxrwxrwt 14 root root 4096 Dec  6 02:46 tmp
/var# cd mail
/var/mail# echo $PWD
/var/mail

/var/mail# pwd
/var/mail

/var/mail# /bin/pwd
/var/spool/mail

, $PWD , pwd ( ) .

? /bin/pwd , , - Linux ​​ (. /proc/self/cwd), , , .

+2

/bin/pwd , , cd , , - ; , , realpath().

. set -o physical bash.

+2

Source: https://habr.com/ru/post/1778653/


All Articles