0

I just discovered that on my system (Fedora 35), all of Bash's builtin commands also exist as scripts in /usr/bin. For instance:

$ which cd
/usr/bin/cd
$ cat $(which cd)
#!/usr/bin/sh
builtin cd "$@"

With the same thing applying to read, bg, etc for all Bash builtins.

What is this builtin command, and what is the point of creating scripts for all builtin commands like this?

  • POSIX requires that certain commands like `cd` be installed as commands. However, using `/usr/bin/cd` is a no-op since it operates outside the shell and cannot change the shell's current working directory. [Standards](https://xkcd.com/927) are not always helpful. – doneal24 Apr 27 '22 at 22:33
  • similarly `read` can't be implemented as an external process, since it needs to write what it read in the shell's memory; external `fg`, `bg` and `wait` can't know what the shell's child processes are and wouldn't get termination notices for them; an external `umask` would only change the mask for itself, not the shell... An external `pwd` should work ok, though. – ilkkachu Apr 27 '22 at 22:50
  • @ilkkachu I've actually seen vendor-provided shell scripts that call `/usr/bin/cd`. It is painful to interact with customer support in these cases. :( – doneal24 Apr 27 '22 at 23:06

0 Answers0