A minimal unix shell written in C, built in 2023 to learn how shells actually work under the hood - process creation, program exectution, and terminal I/O without any libraries beyond libc.
- REPL loop - reads a line, tokenizes it, executes, repeats
- Tokenization - splits input on whitespace with a growable token buffer (no fixed argv limit)
- Program exectuion -
fork()+execvp()with a proper wait/exit-status handling in the parent - Built-ins -
exithandled in process (no fork) - Error handling - allocation failures and exec errors reported with colored output
gcc shell.c -o dash
./dash> ls
> echo "hello world"
> exit
The core insight: a shell is just a loop around fork/exec/wait. The subtle parts are memory ownership of the token buffers, distinguishing built-ins (which must run in the shell's own process) from external commands, and resizing input buffers safely as the user types arbitrarily long lines.