This is a completed C solution for the "Build Your Own Shell" Challenge, plus some extra features I added later.
In this challenge, you'll build your own POSIX compliant shell that's capable of interpreting shell commands, running external programs and builtin commands like cd, pwd, echo and more. Along the way, you'll learn about shell command parsing, REPLs, builtin commands, and more.
Note: If you're viewing this repo on GitHub, head over to codecrafters.io to try the challenge.
cshell.mp4
- Cross-platform support (Linux/macOS via
fork/exec, Windows via_spawnv). - Interactive REPL with a
$prompt. - Built-in commands and utilities (see list below).
- External command execution via
PATHlookup, with a fallback to the current directory. - Command parsing with:
- Single and double quotes.
- Backslash escaping (context-aware inside/outside quotes).
- Pipeline support (
|) on non-Windows platforms (multi-stage pipelines). - Redirection support:
>/1>for stdout overwrite>>/1>>for stdout append2>for stderr overwrite2>>for stderr append
- History support on non-Windows platforms:
- Persistent history load/save via
HISTFILE. history -r <file>,history -w <file>,history -a <file>.history [N]to show the last N entries.
- Persistent history load/save via
- Tab autocomplete:
- Linux/macOS: Readline completion for builtins and
PATHexecutables. - Windows: Custom TAB completion for builtins and
PATHexecutables.
- Linux/macOS: Readline completion for builtins and
- ANSI color support for Windows terminals.
- Startup splash screen with randomized ASCII art and rotating status messages.
Alphabetical list of supported commands:
bindump— View a file in binary.cd <dir>— Change directory.clear/cls— Clear the terminal.cshell— Show the theme gallery.echo <txt>— Print text.exit— Close the shell.help— Show built-in help.hexdump— View a file in hex.history— Show or manage history (-r,-w,-a, or a numeric limit).ip— Show network info.ls [-a]— List files (use-afor hidden).mx <domain>— Find mail servers for a domain.ping [host]— Ping a host (defaults to 8.8.8.8).pwd— Print working directory.type <cmd>— Identify builtin or executable path.weather— Get live weather report.whoami— Show current user.
This repository contains a completed solution for the CodeCrafters “Build Your Own Shell” challenge.
- Ensure you have
cmakeinstalled locally. - Run
./your_program.shto build and run the shell (implemented insrc/main.c).