回答:
それはあなたが何をしているかに依存します。まず$PWD、環境変数でpwdあり、組み込みシェルまたは実際のバイナリです。
$ type -a pwd
pwd is a shell builtin
pwd is /bin/pwd
フラグ$PWDを使用しない限り、bashビルトインは現在の値を出力するだけです-P。で説明されているようにhelp pwd:
pwd: pwd [-LP]
Print the name of the current working directory.
Options:
-L print the value of $PWD if it names the current working
directory
-P print the physical directory, without any symbolic links
By default, `pwd' behaves as if `-L' were specified.
pwdバイナリは、一方を介してカレントディレクトリを取得し、getcwd(3)同じ値を返すシステムコールreadlink -f /proc/self/cwd。説明のために、別のディレクトリへのリンクであるディレクトリに移動してみてください。
$ ls -l
total 4
drwxr-xr-x 2 terdon terdon 4096 Jun 4 11:22 foo
lrwxrwxrwx 1 terdon terdon 4 Jun 4 11:22 linktofoo -> foo/
$ cd linktofoo
$ echo $PWD
/home/terdon/foo/linktofoo
$ pwd
/home/terdon/foo/linktofoo
$ /bin/pwd
/home/terdon/foo/foo
だから、結論では、(Ubuntuなど)GNUシステム上で、pwdそしてecho $PWDあなたが使用しない限り等価です-Pオプションが、/bin/pwd異なっていると振る舞うが好きpwd -P。
シンボリックリンクを含め、すべての作業ディレクトリに対してオプションなしで使用すると、どちらも同じ結果を返します。
しかし、からman pwd:
-P, --physical
avoid all symlinks
これはpwd -P、他のディレクトリを指すシンボリックリンクで実行すると、元のディレクトリへのパスが出力されることを意味します。
例として、/var/run指すシンボリックリンク/runがあり、現在/var/run/ディレクトリにいる場合は、次のコマンドを実行します。
echo $PWD
戻ります:
/var/run
と同じになりpwdます。ただし、次を実行した場合:
pwd -P
戻ります
/run
したがって、必要なパスによって異なります。シンボリックリンクのない実際のパス、またはシンボリックリンクを無視する現在のディレクトリです。間の唯一の違いpwd -Pとecho $PWDシンボリックリンクがあるときです。