Skip to content
sarahmss edited this page Dec 21, 2021 · 7 revisions

How a shell works?

As soon as you launch the terminal, you are prompted with commands. If you're on Linux this prompt may take the form of some text followed by a dollar sign which waits for commands to be executed.

Before all this happens, the shell needs some information.

  1. it is handled with an interactive user or a script (cmd_line)
  2. Interpret the context with which it's running (env)
  3. Iteration of an infinite loop (repl)
  4. Sanitize the user’s command (Tokenizer)
  5. Parse commands and set command table (Parse)
  6. Checks if this command is an alias
  7. If it is an alias, substitute for the command it is aliased to.
  8. Compare this command to the names of commands that are built into the shell.
  9. Check if our command is a relative path (in this case, the command will begin with a period .)
  10. Search in its environment for the PATH variable. This environment variable contains paths of the directories that the shell must search, looking for files that match the command.

Clone this wiki locally