Step 4 - Challenge: Commands With Arguments

Step 4 - Challenge: Commands With Arguments

In this step your goal is to be able to run external commands that take arguments, for example ls -la, or cat <filename>.

To do that we’ll need to capture the user input and then split it into parts, the command and the arguments to be passed to the command that we spawn. For example, I’ll run my shell and pass a filename to the cat program, which prints out to the terminal the contents of the file:

% ccsh
ccsh> cat cargo.lock
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3

[[package]]
name = "ccsh"
version = "0.1.0"
ccsh> exit
%

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