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 directory
    • exit — 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.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  ┌─────────┐
    Start  
  └────┬────┘
       
       
┌─────────────┐
  Read line     get command from user
└──────┬──────┘
       
       
┌─────────────┐
  Evaluate      parse + run the command
└──────┬──────┘
       
       
┌─────────────┐
   Print        show output or error
└──────┬──────┘
       
       
┌─────────────┐
   Loop?        exit if user typed "exit"
└──────┬──────┘
       yes
       
     (stop)

Build

1
2
3
4
5
6
# Clone this repository
git clone https://github.com/simocoder/emptyshell.git
cd emptyshell

# Build
cc -std=c11 -Wall -Wextra -O2 -o mtsh mtsh.c

Or use make:

1
make

Install (optional)

You can run mtsh directly from the repo, or install it somewhere in your PATH:

1
sudo cp mtsh /usr/local/bin/

Usage

1
./mtsh

Example session:

$ > / > > e > $ e P h x m O p o c l a e / p S w m d s m x m t I d e p i t y X / / l t s s . u t e h h 1 s m . e - e p t l 2 r x ` l 0 t 0 _ 8 M i n S i i m m a p l l e T e a c H h a i c _ n k , g a b S l h e e l l v 0 . 1

Roadmap Ideas

  • Command history (readline or custom)
  • Tab completion
  • Pipelining (cmd1 | cmd2)
  • I/O redirection
  • Background jobs (&)
  • Configuration files (.mtshrc)

Github

https://github.com/simocoder/emptyshell/