GNU/Linux >> LINUX-Kenntnisse >  >> Linux

Seltsamer Unterschied zwischen Pwd und /bin/pwd?

Ich habe mit ln -s . aa . Wenn ich cd aa ausführe , und danach habe ich pwd ausgeführt , lautet die Antwort /home/sim/aa .

Aber wenn ich /bin/pwd ausführe es gibt /home/sim aus (das aktuelle Verzeichnis hat sich nicht geändert).

Woher kommt dieser Unterschied?

Akzeptierte Antwort:

In den meisten Shells, einschließlich Bash, pwd ist eine eingebaute Shell:

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

Wenn Sie /bin/pwd verwenden , müssen Sie das -L verwenden Option, um das gleiche Ergebnis wie das eingebaute pwd zu erhalten :

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

Standardmäßig /bin/pwd ignoriert symbolische Links und gibt das aktuelle Verzeichnis aus.

Von 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.

Das eingebaute pwd enthält standardmäßig symbolische Links, mit Ausnahme von -P Option verwendet wird, oder -o physical set builtin ist aktiviert.

Von 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. Ist ein Leerzeichen zwischen #! Und /bin/bash in Shebang?

  2. Was ist der Unterschied zwischen /sbin/nologin und /bin/false?

  3. Der Unterschied zwischen /opt und /usr/local?

  4. Linux – Zusammenführen von /usr/bin und /usr/sbin in /bin (gnu/linux)?

  5. Was ist der Unterschied zwischen #!/usr/bin/env bash und #!/usr/bin/bash?

Was ist der Unterschied zwischen /bin/false und /sbin/nologin als Shell des nologin-Benutzers?

Installieren Sie Binärdateien in /bin, /sbin, /usr/bin und /usr/sbin, Interaktionen mit --prefix und DESTDIR

Wann muss ich #!/bin/bash und wann #!/bin/sh verwenden?

Unterschied zwischen /bin und /usr/bin

Was ist der Unterschied zwischen /tmp und /run?

Unterschied zwischen /etc/hosts und /etc/resolv.conf