Step 1 - Challenge: The Simplest Possible Shell

Step 1 - Challenge: The Simplest Possible Shell

In this step your goal is to create the simplest possible command line shell. That’s a program that, starts up and waits for the user to type in a command. To make it easier to see which shell is running I’ve given my shell a unique prompt: ccsh>.

When the user enters a command we’ll need to trim any trailing whitespace or newline characters and then spawn a new process to run the entered command.

For example, here’s what happens when I run my ccsh:

% ccsh
ccsh> ls
LICENSE         README.md       dist            pyproject.toml  src
%

My shell outputs the prompt ccsh>. I have then run the command ls and it has output the results below the prompt. In this case you see the files from my Python implementation of ccsh.

Note that ccsh immediately terminates after running the command, returning me to the normal shell.

Give it a go yourself and read on when you are ready to see how I'd approach it.

Build Your Own Shell (Python Edition)

Buy nowLearn more

Step 0 - Setting Up

  • What We're Going To Build
  • Create a GitHub Repo
  • Setting Up Python

Step 1 - Create The Simplest Possible Command Line Shell

  • Step 1 - Challenge: The Simplest Possible Shell
  • Building The Simple Shell
  • Step 1 - Solution: The Simplest Shell

Step 2 - Challenge: Handle Multiple Commands

  • Step 2 - Challenge: Handling Multiple Commands
  • Exiting From The Shell
  • Handling Multiple Commands
  • Step 2 - Solution: Handling Multiple Commands

Step 3 - Non Existent Commands

  • Step 3 - Challenge: Handling Non-Existent Commands
  • Catching And Handling Errors
  • Step 3 - Solution: Handling Non-Existent Commands

Step 4 - External Commands With Arguments

  • Step 4 - Challenge: Commands With Arguments
  • Handling The Arguments
  • Step 4 - Solution: Handling The Arguments

Step 5 - Built-in Commands

  • Step 5 - Challenge: Implement Builtin Commands
  • Adding The Builtin Commands
  • Step 5 - Solution: Implementing Builtin Commands

Step 6 - Support Pipes

  • Step 6 - Challenge: Supporting Pipes
  • Approaching The Task Of Piping Commands
  • Piping Commands - The Walking Skeleton
  • Supporting Piping For Builtin Commands
  • Step 6 - Solution: Supporting Pipes

Step 7 - Handling Signals

  • Step 7 - Challenge: Handling Signals
  • Handling Signals In Python
  • Step 7 - Solution: Handling Signals

Step 8 - Command History

  • Step 8 - Challenge: Command History
  • Handling History
  • Some Refactoring - Pulling Out Builtins
  • The History Solution
  • Step 8 - Solution: Command History

Conclusion

  • Taking It Further And Wrapping Up