Skip to content

dbislimi/minishell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minishell

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.

Quick Start

make
./minishell

Requires libreadline (apt install libreadline-dev on Debian-based systems).

How it works

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.

Supported features

  • Pipes: cmd1 | cmd2 | cmd3
  • Redirections: >, >>, <, << (heredoc)
  • Environment variable expansion: $VAR, $?
  • Single and double quotes
  • Builtins: echo -n, cd, pwd, export, unset, env, exit

Project structure

├── 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

Releases

No releases published

Packages

 
 
 

Contributors