Project 2: Build Your Own Shell (BYOS)

A functional shell (like bash or zsh, but simpler). It will show a prompt, accept commands (ls -la), handle built-ins (cd, exit), and support input/output redirection (>) and pipes (|).

Quick Reference

Attribute Value
Primary Language C
Alternative Languages Rust, Go
Difficulty Level 2: Intermediate
Time Estimate 1 week
Knowledge Area Process Management / Syscalls
Tooling Linux Terminal, GCC
Prerequisites C basics, Pointers.

What You Will Build

A functional shell (like bash or zsh, but simpler). It will show a prompt, accept commands (ls -la), handle built-ins (cd, exit), and support input/output redirection (>) and pipes (|).

Why It Matters

This project builds core skills that appear repeatedly in real-world systems and tooling.

Core Challenges

  • Parsing: Breaking “ls -la grep foo” into tokens.
  • Fork/Exec pattern: The standard Unix way to run programs.
  • File Descriptors: Making > work by manipulating stdout before exec.
  • Pipes: Connecting the stdout of one process to the stdin of another.

Key Concepts

  • Process Creation: fork(), execvp(), waitpid().
  • File Descriptors: dup2(), open(), close().
  • Signals: Handling Ctrl+C (SIGINT) without killing the shell itself.

Real-World Outcome

$ ./myshell
myshell> ls
file1.txt  file2.c  myshell

myshell> pwd
/home/user/projects/myshell

myshell> ls -l > output.txt
myshell> cat output.txt
(lists files)

myshell> exit

Implementation Guide

  1. Reproduce the simplest happy-path scenario.
  2. Build the smallest working version of the core feature.
  3. Add input validation and error handling.
  4. Add instrumentation/logging to confirm behavior.
  5. Refactor into clean modules with tests.

Milestones

  • Milestone 1: Minimal working program that runs end-to-end.
  • Milestone 2: Correct outputs for typical inputs.
  • Milestone 3: Robust handling of edge cases.
  • Milestone 4: Clean structure and documented usage.

Validation Checklist

  • Output matches the real-world outcome example
  • Handles invalid inputs safely
  • Provides clear errors and exit codes
  • Repeatable results across runs

References

  • Main guide: LEARN_LINUX_UNIX_INTERNALS_DEEP_DIVE.md
  • “The Linux Programming Interface” by Michael Kerrisk