GNU/Linux >> Linux Esercitazione >  >> Linux

Strana differenza tra Pwd e /bin/pwd?

Ho aggiunto un collegamento simbolico alla directory corrente con ln -s . aa . Se eseguo cd aa , e dopo ho eseguito pwd , la risposta è /home/sim/aa .

Ma se eseguo /bin/pwd stampa /home/sim (la directory corrente non è cambiata).

Da dove viene questa differenza?

Risposta accettata:

Nella maggior parte delle shell, inclusa bash, pwd è una shell incorporata:

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

Se usi /bin/pwd , devi usare -L opzione per ottenere lo stesso risultato di pwd integrato :

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

Per impostazione predefinita, /bin/pwd ignora i collegamenti simbolici e stampa la directory effettiva.

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

Il pwd integrato include il collegamento simbolico per impostazione predefinita, tranne che -P viene utilizzata l'opzione, o -o physical set integrato è abilitato.

Da 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. Linux:differenza tra /dev/console , /dev/tty e /dev/tty0?

  2. È consentito lo spazio tra #! E /bin/bash a Shebang?

  3. Qual è la differenza tra /sbin/nologin e /bin/false?

  4. La differenza tra /opt e /usr/local?

  5. La differenza tra '$ . Foo' E '$ ./foo'??

Perché /bin/sh punta a /bin/dash e non a /bin/bash??

Installa i binari in /bin, /sbin, /usr/bin e /usr/sbin, interazioni con --prefix e DESTDIR

Qual è la differenza tra #!/usr/bin/env bash e #!/usr/bin/bash?

Quando dovrei usare /dev/shm/ e quando dovrei usare /tmp/?

Differenza tra /etc/crontab e crontab -e

Differenza tra /bin e /usr/bin