A Unix shell that actually works — pipes, redirections, heredoc, signal handling, and a full AST under the hood. Built to understand what happens between typing a command and seeing its output.
make
./minishellRequires libreadline (apt install libreadline-dev on Debian-based systems).
Input goes through three stages before anything executes.
Tokenizer
The raw input string is split into tokens: words, operators (|, >, >>, <, <<), and quoted strings. Quote detection runs character by character — single quotes disable all interpretation, double quotes allow variable expansion.
Parser → AST
Tokens are assembled into an Abstract Syntax Tree. Each node is a command, a pipe, or a redirection. The tree structure makes operator precedence explicit and separates parsing from execution cleanly.
Executor
The AST is traversed depth-first. Simple commands are forked and exec'd. Pipes are implemented with pipe() + fork(), chaining file descriptors between processes. Redirections call dup2() to remap stdin/stdout before exec. Builtins (echo, cd, pwd, export, unset, env, exit) run in the parent process — forking them would break state like the current directory.
Signals are handled differently depending on context: ctrl-C prints a new prompt in interactive mode, interrupts a running child otherwise.
- Pipes:
cmd1 | cmd2 | cmd3 - Redirections:
>,>>,<,<<(heredoc) - Environment variable expansion:
$VAR,$? - Single and double quotes
- Builtins:
echo -n,cd,pwd,export,unset,env,exit
├── builtins/ — echo, cd, pwd, export, unset, env, exit implementations
├── extender/ — variable expansion and quote handling
├── includes/ — header files
├── libft/ — libft submodule
└── main.c — entry point, readline loop