As beautiful as a shell — 42 Network project
Minishell is a 42 school project that challenges you to create your own simplified version of bash. It involves building a fully functional shell from scratch in C, capable of parsing user input, managing processes, and executing commands — just like a real terminal.
This project is a deep dive into how shells work under the hood: lexing, parsing, process creation, file descriptor management, and signal handling.
- 🔍 Command Execution — Run any system binary via
PATHresolution or absolute paths - 🔀 Pipes — Chain commands with
|(e.g.,ls -la | grep .c | wc -l) - 📁 Redirections — Input
<, output>, append>>, and heredoc<< - 💲 Environment Variables — Expand
$VARand$?(last exit status) - 🏠 Built-in Commands:
echo(with-nflag)cd(relative and absolute paths)pwdexport/unsetenvexit
- 🔔 Signal Handling —
Ctrl+C,Ctrl+D,Ctrl+\behave like in bash - 📝 Command History — Navigate previous commands with arrow keys
- 🔗 Quote Handling — Single
'and double"quotes with proper parsing
- GCC compiler
- Make
readlinelibrary (sudo apt install libreadline-devon Ubuntu)- A UNIX-based OS (Linux / macOS)
git clone https://github.com/JMADIL/MINISHELL.git
cd MINISHELL
make./minishellYou'll be greeted with a prompt where you can type commands just like in bash:
minishell$ echo "Hello World"
Hello World
minishell$ ls -la | grep .c | wc -l
3
minishell$ export MY_VAR="42"
minishell$ echo $MY_VAR
42
minishell$ exit
MINISHELL/
├── Makefile # Build system
├── minishell.c # Entry point & main loop (prompt, read, execute)
├── minishell.h # Header with structs, prototypes & includes
├── cleaning.c # Memory cleanup & free functions
├── pars/ # Parsing module (lexer, tokenizer, AST)
└── exec/ # Execution module (builtins, pipes, redirections)
┌─────────────────────────────────────────────────────┐
│ MINISHELL │
├─────────────────────────────────────────────────────┤
│ │
│ Input ──► Lexer ──► Parser ──► Executor ──► Output│
│ │ │ │ │
│ readline() Token List fork/execve │
│ + AST + pipes │
│ + redirections │
│ │
├─────────────────────────────────────────────────────┤
│ Built-ins: echo, cd, pwd, export, unset, env, exit │
└─────────────────────────────────────────────────────┘
| Concept | Description |
|---|---|
| Lexing & Parsing | Tokenizing raw input and building an abstract syntax tree |
| Process Management | Creating child processes with fork() and execve() |
| Pipes | Inter-process communication via pipe() and file descriptors |
| Redirections | Manipulating stdin/stdout with dup2() |
| Signals | Handling SIGINT, SIGQUIT, SIGTERM in parent and child |
| Environment | Managing environment variables as a linked list |
| Memory Management | Preventing leaks with proper cleanup routines |
Adil Jamoun — @JMADIL & @ilyasrf
🏫 1337 Coding School (42 Network) — Morocco