GNU/Linux >> Znalost Linux >  >> Linux

Podivný rozdíl mezi Pwd a /bin/pwd?

Do aktuálního adresáře jsem přidal symbolický odkaz pomocí ln -s . aa . Pokud spustím cd aa a poté jsem provedl pwd , odpověď je /home/sim/aa .

Ale když spustím /bin/pwd vypíše /home/sim (aktuální adresář se nezměnil).

Kde se bere tento rozdíl?

Přijatá odpověď:

Ve většině shellů včetně bash pwd je vestavěný shell:

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

Pokud používáte /bin/pwd , musíte použít -L možnost získat stejný výsledek jako vestavěný pwd :

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

Ve výchozím nastavení /bin/pwd ignoruje symbolické odkazy a vytiskne skutečný adresář.

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

Vestavěný pwd ve výchozím nastavení obsahuje symbolický odkaz, kromě -P je použita volba nebo -o physical sada vestavěná je povolena.

Z 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:Rozdíl mezi /dev/console, /dev/tty a /dev/tty0?

  2. Rozdíl mezi 2>&-, 2>/dev/null, |&, &>/dev/null A>/dev/null 2>&1?

  3. Je povoleno místo mezi #! A /bin/bash v Shebangu?

  1. Jaký je rozdíl mezi /sbin/nologin a /bin/false?

  2. Rozdíl mezi /opt a /usr/local?

  3. Rozdíl mezi „$ . Foo“ A „$ ./foo“??

  1. Linux – sloučení /usr/bin A /usr/sbin do /bin (gnu/linux)?

  2. Proč /bin/sh ukazuje na /bin/dash a ne /bin/bash?

  3. Rozdíl mezi /etc/crontab a crontab -e