2

I suggested using which to confirm whether a command works only as a shell builtin or alias. cd is an example of a command that works as a shell builtin. It would be much harder to implement the same function as a binary...

So why does my Fedora system have a binary /usr/bin/cd? It doesn't implement the magic necessary to affect the shell (parent process) working directory, to match the behaviour of the cd builtin. My Debian 8 system doesn't have /usr/bin/cd.

$ command -v sudo
/usr/bin/sudo
$ command -v cd
cd
$ which sudo
/usr/bin/sudo
$ which cd
/usr/bin/cd
$ rpm -q --whatprovides /usr/bin/cd
bash-4.3.43-4.fc25.x86_64
$ (. /etc/os-release && echo $PRETTY_NAME)
Fedora 25 (Workstation Edition)
$ pwd
/home/alan
$ cd /home && pwd
/home
$ /usr/bin/cd /home/alan && pwd
/home
$ cd --help
bash: cd: --: invalid option
cd: usage: cd [-L|[-P [-e]] [-@]] [dir]

The full list of binaries provided by the bash package is

$ rpm -q --dump bash|grep /usr/bin|cut -f 1 -d ' '|cut -f 4

alias bash bashbug bashbug-64 bg cd command fc fg getopts hash jobs read sh type ulimit umask unalias wait

sourcejedi
  • 50,249

0 Answers0