Shell – Why cd is Not a Program

cd-commandcommandshellshell-builtin

I've always wondered why cd isn't a program, but never managed to find the answer.

Anyone know why this is the case?

Best Answer

The cd command modifies the "current working directory", right?

"current working directory" is a property that is unique to each process.

So, if cd was a program it would work like this:

  1. cd foo
  2. the cd process starts
  3. the cd process changes the directory for the cd process
  4. the cd process exits
  5. your shell still has the same state, including current working directory, that it did before you started.