Step 2 - Challenge: Handling Multiple Commands

Step 2 - Challenge: Handling Multiple Commands

In this step your goal is to handle multiple commands. To do that you’ll want to wrap your existing command handling code in a loop. We want that loop to continue indefinitely, but we will also want to be able to exit from the shell.

To allow us to exit the shell most commands offer a builtin command - I bet you can’t guess what the command is! 😀

So to complete this step, extend your shell to accept multiple commands until the user enters the builtin command: exit.

That should look something like this:

% ccsh
ccsh> ls
LICENSE         README.md       dist            pyproject.toml  src
ccsh> pwd
/Users/johncrickett/dev/pyccsh
ccsh> exit
%

Don’t forget to make your shell wait for the running command to finish before trying to capture the next command from a user.

Give it a go now, and move on to the next lesson when you're stuck/ready to see how I approached 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