Writing a shell in python

Rishub Kumar
1 min readMay 7, 2022

UNIX is very simple, it just needs a genius to understand its simplicity. — Dennis Ritchie

What is a shell?

Already a lot of definition online, so a simple one would be:

A shell is an interface that allows you to interact with the kernel of an operating system.

Some examples of shells are:

How does a shell work?

A shell parses commands entered by the user and executes this. To be able to do this, the workflow of the shell will look like this:

  1. Startup the shell
  2. Wait for user input
  3. Parse user input
  4. Execute the command and return the result
  5. Go back to 2.

There is one important piece to all of this though: processes. The shell is the parent process. This is the main thread of our program which is waiting for user input. However, we cannot execute the command in the main thread itself, because of the following reasons:

  1. An erroneous command will cause the entire shell to stop working. We want to avoid this.
  2. Independent commands should have their own process blocks. This is known as isolation and falls under fault tolerance.

Source code

Github: https://github.com/itsrishub/MyShell

--

--

Rishub Kumar

Computer science student, developer. I write my white papers(research) work and about coding stuff here.