GNU/Linux >> Linux の 問題 >  >> Linux

Pwdと/bin/ pwdの奇妙な違いは?

ln -s . aacd aaを実行すると 、その後、pwdを実行しました 、応答は/home/sim/aaです。 。

しかし、/bin/pwdを実行すると /home/simを出力します (現在のディレクトリは変更されていません。)

この違いはどこから来るのですか?

承認された回答:

bashを含むほとんどのシェルでは、pwd シェルビルトインです:

$ type -a pwd
pwd is a shell builtin
pwd is /bin/pwd

/bin/pwdを使用する場合 、-Lを使用する必要があります 組み込みのpwdと同じ結果を取得するオプション :

$ ln -s . test
$ cd test && pwd
/home/cuonglm/test
$ /bin/pwd
/home/cuonglm
$ /bin/pwd -L
/home/cuonglm/test

デフォルトでは、/bin/pwd シンボリックリンクを無視し、実際のディレクトリを出力します。

info pwdから :

`-L'
`--logical'
     If the contents of the environment variable `PWD' provide an
     absolute name of the current directory with no `.' or `..'
     components, but possibly with symbolic links, then output those
     contents.  Otherwise, fall back to default `-P' handling.

`-P'
`--physical'
     Print a fully resolved name for the current directory.  That is,
     all components of the printed name will be actual directory
     names--none will be symbolic links.

組み込みのpwd -Pを除いて、デフォルトでシンボリックリンクが含まれます オプションを使用するか、-o physical setbuiltinが有効になっています。

man bashから :

pwd [-LP]
              Print the absolute pathname of the  current  working  directory.
              The pathname printed contains no symbolic links if the -P option
              is supplied or the -o physical option to the set builtin command
              is  enabled.  If the -L option is used, the pathname printed may
              contain symbolic links.  The return status is 0 unless an  error
              occurs  while  reading  the  name of the current directory or an
              invalid option is supplied.

Linux
  1. / bin/falseと/sbin/nologinの違い

  2. Linux:/ dev / console、/ dev / tty、/ dev / tty0の違いは?

  3. 2>&-、2> / dev / null、|&、&> / dev/nullと>/dev / null 2>&1の違いは?

  1. /optと/usr/ localの違いは?

  2. ‘$の違い。 Foo」と「$./foo」??

  3. / bin/shが/bin/bashではなく/bin/ dashを指すのはなぜですか?

  1. nologin ユーザーのシェルとしての /bin/false と /sbin/nologin の違い

  2. バイナリを /bin、/sbin、/usr/bin、および /usr/sbin にインストールし、 --prefix および DESTDIR と対話します

  3. #!/usr/bin/env bash と #!/usr/bin/bash の違いは何ですか?