Interview Prep/Shell Scripting/Shells, scripts and execution

Why must `cd`, `export` and `read` be builtins rather than external programs?

IntermediateConceptShells, scripts and execution
Answer

An external program runs in a child process, and a child cannot change its parent's state. If cd were /usr/bin/cd, it would change the child's directory and exit, leaving your shell where it was. The same applies to export (shell environment), read (sets shell variables), set, trap, exit and source. That is also why sudo cd /root fails: sudo can only exec programs.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Shells, scripts and execution