In "Change Directory with cd", cd was "part of the shell, not a separate program". Commands like this are builtins. The shell runs them itself, with no program file.
| Builtin | Does |
|---|---|
cd | Changes the current directory |
echo | Writes its arguments |
export | Puts a variable in the environment |
history | Shows the command history |
type | Tells you what a command name is |
Why cd must be a builtin
A program runs as a child process. A child cannot change its parent, the same as with variables. If cd were a program, it would change only its own directory, then end. Your shell would stay where it was.
type: what is this name?
type tells you what the shell runs for a name:
text
learner@tidepool:~$ type cd
cd is a shell builtin
learner@tidepool:~$ type grep
grep is /usr/bin/greptype NAME writes | The name is |
|---|---|
NAME is a shell builtin | Part of the shell |
NAME is /usr/bin/NAME | A program file, found with PATH |
NAME is aliased to ... | An alias, the next lesson |
which finds only program files. type knows all three kinds.
help: the help of a builtin
Builtins have no program file and often no manual page. The shell's own help command shows their help:
text
learner@tidepool:~$ help cd
cd: cd [-L|-P] [dir]
Change the shell working directory.