Coding Challenge #14 - Build Your Own Shell

Coding Challenge #14 - Build Your Own Shell

This challenge is to build your own shell.

A shell is a program that exposes the operating system’s services to us, the user of the system. We’re going to focus on the command line versions, like sh, bash, zsh and others.

Coding Challenges Live - A Cohort Training Course

Would you like to tackle one of these coding challenges with a cohort of other software engineers - and me?

I’m building a three-week cohort-based course around a coding challenges On the course you’ll learn:

  1. How the application is built - the data structures, algorithms, and architecture behind it.
  2. How to tackle the project in stages - breaking it down into a series of steps and testing as you go.
  3. How to collaborate with other software engineers - reviewing their code and offering feedback on their solutions.

If that sounds interesting, you can register your interest and provide feedback on which challenge you’d like to cover here: https://maven.com/forms/cfd972

I’ll be offering a 50% discount to everyone who fills out the survey.

Ok let’s get into the challenge of building a shell….


The Challenge - Building Your Own Shell

I use zsh on my MacBook, here’s what the man page says about it:

Zsh is a UNIX command interpreter (shell) usable as an 
interactive login shell and as a shell script command 
processor.        

We’re going to build our shell, which will enable us to run commands on our operating system.


Step Zero

Please set up your IDE / editor and programming language of choice and proceed directly to step 1 once you’re ready. I’ve called my project ccsh for Coding Challenges Shell.


Step 1

In this step your goal is to create the simples possible command line shell. That’s a program that starts up 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
Cargo.lock      Cargo.toml      src             target
%         

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 Rust implementation of ccsh.

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


Continued...

You can find Step 2 and beyond on the?Coding Challenges?website as?Write You Own Shell.

Or if you'd rather get the whole challenge delivered to you inbox every week, you can subscribe on the?Coding Challenges Substack.

Mohit Jain

Software Tech Lead @Zemetric | ex Co-Founder @Evy Energy (Acquired)

1 å¹´

John Crickett. This was an interesting one. I learned a lot about spawning child processes and how to test them as well. Here's my solution in TS: https://github.com/jainmohit2001/coding-challenges/tree/master/src/14

Sarah Gruneisen ??

Engineering Manager | Leadership Trainer | Author | Complexity Buster & Motivator | Keynote Speaker | Certified Leadership Coach | 20+ in Software Engineering | 15+ in Leadership | ? Addict

1 å¹´

Level up your coding skills like a dragon hoards treasure. Take on the challenge and watch your code fire up! ??. Love this list! Will store it for my own teams to take advantage of!

Rehan Sattar

Senior Software Engineer | Full Stack Developer | Public Speaker at Global Tech Events

1 å¹´

Practice is the most powerful tool to be good at software development ?? Thanks for sharing John Crickett

要查看或添加评论,请登录

John Crickett的更多文章

  • From The Challenges - Memcached Server

    From The Challenges - Memcached Server

    ?? ?? Happy Birthday Coding Challenges - Two Years Old! ?? ?? Coding Challenges is turning two this week! To celebrate…

    13 条评论
  • Coding Challenge #85 - Time Zone Converter

    Coding Challenge #85 - Time Zone Converter

    Coding Challenge #85 - Time Zone Converter This challenge is to build your own Time Zone Converter. That is a tool to…

    12 条评论
  • From The Challenges - IRC Client

    From The Challenges - IRC Client

    Welcome To Coding Challenges - From The Challenges! In this Coding Challenges “from the challenges” newsletter I’m…

    5 条评论
  • Coding Challenge #84 - Mandelbrot Set Explorer

    Coding Challenge #84 - Mandelbrot Set Explorer

    This challenge is to build your own Mandelbrot set explorer. The Mandelbrot set is a set of fractals that exhibit great…

    4 条评论
  • From The Challenges - Cat

    From The Challenges - Cat

    Welcome To Coding Challenges - From The Challenges! In this Coding Challenges “from the challenges” newsletter I’m…

    7 条评论
  • Coding Challenge #83 - Markdown Presentation Tool

    Coding Challenge #83 - Markdown Presentation Tool

    Coding Challenge #83 - Markdown Presentation Tool This challenge is to build your own version of Go’s Present or…

    3 条评论
  • From The Challenges - Shell

    From The Challenges - Shell

    Welcome To Coding Challenges - From The Challenges! In this Coding Challenges “from the challenges” newsletter I’m…

    3 条评论
  • Coding Challenge #82 - Markdown To PDF Editor

    Coding Challenge #82 - Markdown To PDF Editor

    Coding Challenge #82 - Markdown To PDF Editor This challenge is to build your own tool to convert markdown to PDF. It…

    14 条评论
  • From The Challenges - Diff

    From The Challenges - Diff

    Welcome To Coding Challenges - From The Challenges! In this Coding Challenges “from the challenges” newsletter I’m…

    7 条评论
  • Coding Challenge #81 - Brainf*ck Interpreter

    Coding Challenge #81 - Brainf*ck Interpreter

    This challenge is to build your own Brainf*ck Interpreter. Just in case you’re wondering, yes the * should be a u, but…

    34 条评论

社区洞察

其他会员也浏览了