mtsh (pronounced like em tee shell) is a tiny, educational Unix-like shell written in C.
It’s designed to be simple enough to understand line-by-line, while still being a functional interactive shell you can extend over time.
It starts as a bare-bones REPL that can run external commands, and is designed to grow feature-by-feature as you learn. Every line of code is intended to be readable, hackable, and easily extended — making mtsh a hands-on guide to understanding how real shells work under the hood.
Features
- POSIX.1-2008 compliant — portable across most modern Unix-like systems.
- Minimal command loop:
- Reads a line of input
- Parses it into arguments
- Runs external commands via
execvp()
- Built-in commands:
cd
— change the working directoryexit
— quit the shell
- Proper signal and exit code handling.
Why mtsh?
There are many full-featured shells. mtsh is not one of these!
Instead, it’s a teaching tool: a clean starting point for learning shell internals without wading through tens of thousands of lines of code.
You can:
- Experiment with process management.
- Add more built-ins.
- Implement piping, redirection, job control, or scripting support.
- Learn by modifying a shell you fully understand.
|
|
Build
|
|
Or use make
:
|
|
Install (optional)
You can run mtsh directly from the repo, or install it somewhere in your PATH
:
|
|
Usage
|
|
Example session:
Roadmap Ideas
- Command history (
readline
or custom) - Tab completion
- Pipelining (
cmd1 | cmd2
) - I/O redirection
- Background jobs (
&
) - Configuration files (
.mtshrc
)