Skip to content

Unix shell implementation in C that supports command execution, built-in commands, and process management.

Notifications You must be signed in to change notification settings

ITAXBOX/MINI_SHELL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš MINISHELL - A Bash-like Shell Implementation

Minishell Banner

42 School C Shell

A fully-featured, memory-safe shell implementation built from scratch

Recreating the magic of bash with advanced features, robust error handling, and production-quality memory management


๐ŸŽฏ Project Overview

Minishell is a comprehensive shell implementation that replicates the core functionality of bash. This project demonstrates mastery of:

  • System Programming - Process creation, inter-process communication, signal handling
  • Memory Management - Custom garbage collector, leak prevention, buffer overflow protection
  • Parsing & Lexical Analysis - Command parsing, variable expansion, wildcard matching
  • Advanced Shell Features - Pipelines, redirections, built-in commands, environment management

โœจ Key Features

๐Ÿ”ง Core Shell Functionality

  • Interactive Command Line with readline integration
  • Command Execution with PATH resolution
  • Built-in Commands: echo, cd, pwd, export, unset, env, exit
  • Environment Variable Management with dynamic expansion

๐Ÿš€ Advanced Features

  • Pipeline Support - Multi-command pipelines with proper process management
  • I/O Redirection - Input/Output redirection (<, >, >>)
  • Here Documents - Interactive input with delimiters (<<)
  • Variable Expansion - Dynamic variable substitution ($VAR, $?)
  • Wildcard Matching - Glob pattern expansion (*.c)
  • Signal Handling - Proper SIGINT and SIGQUIT handling

๐Ÿ›ก๏ธ Robust Architecture

  • Memory Safety - Custom garbage collector prevents leaks
  • Error Handling - Comprehensive error management with proper exit codes
  • Debug Mode - Built-in debugging capabilities for development
  • Valgrind Clean - Zero memory leaks, production-ready

๐Ÿ” Debug Mode Capabilities

Debug Mode

Advanced debugging features showing tokenization, parsing, and execution flow


๐Ÿ“‹ Development Journey

๐Ÿ—‚๏ธ Project Management & Problem Solving

Kanban Board Our systematic approach to tackling complex challenges through organized task management

Key Challenges Conquered:

  • โœ… Memory Management - Implemented dual garbage collectors for command vs environment memory
  • โœ… Buffer Overflow Prevention - Dynamic allocation for variable expansion
  • โœ… Fork Memory Leaks - Child process memory cleanup
  • โœ… Signal Handling - Proper signal management in interactive mode
  • โœ… Pipeline Execution - Complex multi-process coordination
  • โœ… Variable Expansion - Safe, dynamic string processing
  • โœ… Wildcard Matching - Efficient glob pattern implementation

๐Ÿ—๏ธ Architecture & Design

๐Ÿ“ Project Structure

minishell/
โ”œโ”€โ”€ ๐ŸŽฏ Core
โ”‚   โ”œโ”€โ”€ minishell.c          # Main program loop
โ”‚   โ”œโ”€โ”€ minishell.h          # Global definitions
โ”‚   โ””โ”€โ”€ Makefile            # Build system
โ”œโ”€โ”€ ๐Ÿง  Lexer & Parser
โ”‚   โ”œโ”€โ”€ lexer/              # Tokenization & variable expansion
โ”‚   โ””โ”€โ”€ parser/             # Command parsing & AST generation
โ”œโ”€โ”€ โš™๏ธ Executor  
โ”‚   โ”œโ”€โ”€ executor/           # Command execution & built-ins
โ”‚   โ””โ”€โ”€ signals/            # Signal management
โ”œโ”€โ”€ ๐Ÿ”ง Utilities
โ”‚   โ”œโ”€โ”€ utils/              # Helper functions & utilities
โ”‚   โ””โ”€โ”€ gc/                # Garbage collection system
โ””โ”€โ”€ ๐Ÿ“Š Debug
    โ””โ”€โ”€ debugging/          # Development & debugging tools

๐Ÿงฉ Core Components

๐ŸŽ›๏ธ Dual Garbage Collector System

typedef struct s_minishell {
    t_gc    gc;        // Command-specific memory (cleaned per command)
    t_gc    env_gc;    // Environment memory (persistent across commands)
    // ... other components
} t_minishell;

๐Ÿ”„ Execution Flow

  1. Input Processing โ†’ Tokenization โ†’ Parsing โ†’ AST Generation
  2. Command Resolution โ†’ Built-in Detection โ†’ PATH Lookup
  3. Process Management โ†’ Fork/Exec โ†’ Pipeline Coordination
  4. Memory Cleanup โ†’ Garbage Collection โ†’ Resource Deallocation

๐Ÿš€ Getting Started

๐Ÿ“‹ Prerequisites

  • GCC compiler
  • GNU Readline library
  • Make build system
  • Linux/Unix environment

๐Ÿ› ๏ธ Installation

# Clone the repository
git clone <repository-url>
cd MINI_SHELL

# Build the project
make

# Run minishell
./minishell

๐ŸŽฎ Usage Examples

# Basic commands
minishell$ echo "Hello, World!"
minishell$ pwd
minishell$ cd /tmp

# Pipelines
minishell$ ls -la | grep "\.c" | wc -l

# Variable expansion
minishell$ export MY_VAR="test"
minishell$ echo $MY_VAR

# Redirections
minishell$ echo "Hello" > output.txt
minishell$ cat < input.txt >> output.txt

# Here documents
minishell$ cat << EOF
> This is a here document
> EOF

๐Ÿ”ง Development Mode

# Enable debug mode
make debug
./minishell

# Clean build
make clean && make

๐Ÿงช Testing & Quality Assurance

โœ… Memory Safety

  • Valgrind Clean - Zero memory leaks detected
  • Buffer Overflow Protection - Dynamic allocation prevents crashes
  • Double-Free Prevention - Garbage collector manages all allocations

๐ŸŽฏ Feature Coverage

  • Built-in Commands - All bash built-ins implemented
  • Pipeline Testing - Complex multi-command pipelines
  • Edge Cases - Comprehensive error handling
  • Signal Testing - Proper signal behavior verification

๐Ÿ“Š Performance Metrics

  • Memory Usage - Efficient allocation with automatic cleanup
  • Execution Speed - Optimized command processing
  • Reliability - Robust error handling and recovery

๐Ÿ‘ฅ Team & Contributions

This project represents collaborative excellence in system programming, showcasing:

  • Advanced C Programming - Complex data structures, memory management
  • System Programming - Process control, IPC, signal handling
  • Software Architecture - Clean, maintainable, scalable design
  • Problem Solving - Systematic approach to complex challenges
  • Team Collaboration - Coordinated development using Kanban methodology

๐Ÿ† Achievements

๐ŸŽ–๏ธ Technical Excellence

  • โœ… Zero Memory Leaks - Production-grade memory management
  • โœ… Full Bash Compatibility - Complete feature implementation
  • โœ… Advanced Debugging - Comprehensive development tools
  • โœ… Robust Architecture - Scalable, maintainable codebase

๐Ÿ“ˆ Learning Outcomes

  • System Programming Mastery - Deep understanding of Unix systems
  • Memory Management Expertise - Custom allocator implementation
  • Advanced C Skills - Complex project architecture in C
  • Software Engineering - Professional development practices

๐ŸŒŸ Built with Excellence at 42 Beirut

Where passion meets precision in systems programming

"The best way to learn systems programming is to build a system."

ยฉ 2025 - Crafted with โค๏ธ and countless hours of debugging

About

Unix shell implementation in C that supports command execution, built-in commands, and process management.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •