Coding Challenge #14 - Build Your Own Shell
John Crickett
Helping you become a better software engineer by building real-world applications.
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:
- How the application is built - the data structures, algorithms, and architecture behind it.
- How to tackle the project in stages - breaking it down into a series of steps and testing as you go.
- 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.
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
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!
Interesting one this week John ??
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