Skip to content

JudaNanaa/minishell_broken

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

46 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Minishell

A comprehensive implementation of a Unix shell written in C, featuring advanced parsing, execution, and shell functionality.

πŸ“‹ Table of Contents

🎯 Overview

Minishell is a complete shell implementation that replicates the behavior of bash, including command parsing, execution, environment variable management, and advanced shell features. The project demonstrates deep understanding of system programming, process management, and shell internals.

✨ Features

Core Shell Functionality

  • Interactive shell with custom prompt
  • Command execution with proper process management
  • Environment variable handling and expansion
  • Signal handling (Ctrl+C, Ctrl+D, Ctrl+)
  • Exit status management
  • Subshell execution with -c option

Advanced Parsing

  • Lexical analysis with tokenization
  • Abstract Syntax Tree (AST) construction
  • Quote handling (single and double quotes)
  • Variable expansion with proper escaping
  • Command chaining with && and || operators

Redirections & Pipes

  • Input redirection (<)
  • Output redirection (>, >>)
  • Here documents (<<)
  • Pipes (|) with multiple pipe support
  • File descriptor management

Wildcard Expansion

  • Glob pattern matching (*)
  • Directory traversal for wildcard expansion
  • Path resolution with absolute and relative paths

Additional Features

  • Command history with readline integration
  • Alias support with persistent storage
  • Custom prompt with user and directory display
  • Garbage collection for memory management
  • Comprehensive error handling

πŸ—οΈ Project Structure

minishell/
β”œβ”€β”€ includes/           # Header files
β”‚   β”œβ”€β”€ minishell.h
β”‚   β”œβ”€β”€ includes.h
β”‚   └── error.h
β”œβ”€β”€ srcs/              # Source code
β”‚   β”œβ”€β”€ main.c         # Entry point
β”‚   β”œβ”€β”€ ast/           # Abstract Syntax Tree
β”‚   β”œβ”€β”€ builtins/      # Built-in commands
β”‚   β”œβ”€β”€ exec/          # Command execution
β”‚   β”œβ”€β”€ parsing/       # Lexer and parser
β”‚   β”œβ”€β”€ wildcard/      # Wildcard expansion
β”‚   β”œβ”€β”€ features/      # History, prompt, aliases
β”‚   β”œβ”€β”€ signal/        # Signal handling
β”‚   β”œβ”€β”€ environment/   # Environment management
β”‚   β”œβ”€β”€ garbage_collector/ # Memory management
β”‚   └── utils/         # Utility functions
β”œβ”€β”€ libft/             # Custom C library
β”œβ”€β”€ bin/               # Test scripts
└── Makefile           # Build configuration

πŸš€ Installation

Prerequisites

  • GCC compiler
  • Make
  • Readline library
  • Linux/Unix environment

Build Instructions

  1. Clone the repository

    git clone <repository-url>
    cd minishell
  2. Compile the project

    make
  3. Run minishell

    ./minishell

Build Options

  • make all - Compile the project
  • make clean - Remove object files
  • make fclean - Remove all generated files
  • make re - Rebuild the project
  • make leak - Run with Valgrind for memory leak detection

πŸ’» Usage

Interactive Mode

./minishell

Command Mode

./minishell -c "echo Hello World"

Example Commands

# Basic commands
ls -la
pwd
echo "Hello World"

# Environment variables
export MY_VAR="test"
echo $MY_VAR

# Pipes and redirections
ls -l | grep ".c" > output.txt
cat < input.txt

# Command chaining
ls && echo "Success" || echo "Failed"

# Wildcards
ls *.c
echo /usr/bin/*

# Here documents
cat << EOF
This is a here document
EOF

πŸ”§ Built-in Commands

Command Description Example
echo Print arguments echo "Hello World"
cd Change directory cd /home/user
pwd Print working directory pwd
export Set environment variables export VAR=value
unset Unset environment variables unset VAR
env Print environment variables env
exit Exit the shell exit 0
alias Create command aliases alias ll="ls -la"

🎯 Advanced Features

Parsing Engine

  • Lexical Analysis: Tokenizes input into meaningful units
  • Syntax Analysis: Builds Abstract Syntax Tree for command structure
  • Error Recovery: Handles syntax errors gracefully

Execution Engine

  • Process Management: Fork/exec for command execution
  • Signal Handling: Proper signal propagation and handling
  • File Descriptor Management: Redirection and pipe implementation

Memory Management

  • Garbage Collection: Automatic memory cleanup
  • Memory Safety: Comprehensive error handling and cleanup

πŸ§ͺ Testing

The project includes comprehensive test suites:

Basic Tests

./bin/test_basic.sh

Bonus Features Tests

./bin/test_bonus.sh

Specific Feature Tests

./bin/test_cd.sh      # Directory navigation
./bin/test_echo.sh    # Echo command
./bin/test_export.sh  # Environment variables
./bin/test_pipes.sh   # Pipe functionality

Memory Leak Testing

./bin/test_valgrind.sh

Run All Tests

./bin/run_test.sh

πŸ› οΈ Development

Code Style

  • Follows 42 coding standards
  • Uses custom libft library
  • Comprehensive error handling
  • Memory leak prevention

Debugging

make debug    # Launch with LLDB debugger
make leak     # Run with Valgrind

πŸ‘₯ Contributors

πŸ” Technical Details

Architecture

  • Modular Design: Separated concerns with clear interfaces
  • AST-based Parsing: Robust command structure representation
  • Process-based Execution: Proper Unix process management
  • Memory Safety: Garbage collection and error handling

Key Components

  • Lexer: Tokenizes shell input
  • Parser: Builds command structure
  • Executor: Manages process execution
  • Builtins: Implements shell commands
  • Environment: Manages variables and state

This minishell implementation demonstrates advanced C programming concepts, system programming, and shell internals understanding.

About

The minishell

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors