Skip to content

Caio-de-Souza-Marinho/minishell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

241 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project has been created as part of the 42 curriculum by caide-so, marcudos.

Minishell

As beautiful as a shell


Description

Minishell is a simplified Unix shell implementation built as part of the 42 School curriculum. The goal is to recreate the core behavior of bash, gaining hands-on understanding of how shells work under the hood — from parsing user input to managing processes, file descriptors, and signals.

This project covers the entire pipeline of a shell:

  • Tokenization — breaking raw input into meaningful tokens
  • Syntax analysis — validating token structure before execution
  • AST (Abstract Syntax Tree) construction — representing command logic as a tree
  • Expansion — handling environment variables, $?, wildcards, and quote rules
  • Execution — running builtins, external commands, pipes, redirections, and subshells
  • Signal handling — responding correctly to Ctrl-C, Ctrl-D, and Ctrl-\

Features

Mandatory

  • Interactive prompt with command history
  • Executable lookup via PATH, relative, and absolute paths
  • Single and double quote handling
  • Environment variable expansion ($VAR, $?)
  • Redirections: <, >, >>, << (heredoc)
  • Pipes (|) connecting command outputs to inputs
  • Signal handling: Ctrl-C, Ctrl-D, Ctrl-\
  • Built-in commands:
    • echo (with -n)
    • cd (relative and absolute paths)
    • pwd
    • export
    • unset
    • env
    • exit

Bonus

  • Logical operators && and || with parenthesis-based priority
  • Wildcard * expansion in the current working directory

Instructions

Requirements

  • GCC compiler
  • GNU Make
  • readline library (libreadline-dev on Debian/Ubuntu)

Compilation

# Clone the repository
git clone  minishell
cd minishell

# Build the project
make

# Build with bonus features
make bonus

Running

./minishell

Cleanup

# Remove object files
make clean

# Remove object files and binary
make fclean

# Full recompile
make re

Memory Check (optional)

A readline.supp valgrind suppression file is included to filter readline's known leaks:

make leak

Project Structure

minishell/
├── include/
│   ├── minishell.h       # Main header with all function prototypes
│   ├── structs.h         # All struct and enum definitions
│   └── colors.h          # ANSI color macros for the prompt
├── src/
│   ├── main.c            # Entry point, prompt loop, parser
│   ├── tokenizer/        # Input → token list
│   ├── syntax/           # Token validation
│   ├── ast/              # Token list → AST
│   ├── expansion/        # Variable, wildcard, and quote expansion
│   ├── executor/         # AST execution, pipes, redirections
│   ├── builtin/          # Built-in command implementations
│   ├── heredoc/          # Heredoc input processing
│   ├── signal/           # Signal handler setup
│   ├── env/              # Environment variable management
│   ├── prompt/           # Prompt string construction
│   └── clean/            # Memory cleanup utilities
├── libft/                # Personal C utility library
└── Makefile

Resources

Official Documentation

Articles & Tutorials

42-Specific References


AI Usage

AI tools (primarily Claude) were used during this project in the following ways:

  • Debugging assistance — describing unexpected behaviors and getting suggestions on where to investigate (e.g., signal handling edge cases, heredoc fd management)
  • Documentation drafting — generating initial function comment blocks, which were then reviewed, corrected, and adapted to match actual implementation
  • Prompt refinement — asking targeted questions about specific POSIX/bash behaviors (e.g., how $? expands inside heredocs, expected exit codes for signals)
  • README structure — this file was drafted with AI assistance and reviewed to ensure accuracy

In all cases, AI-generated content was critically reviewed before use. No logic or implementation was copied from AI output without full understanding — all core algorithms (tokenizer, parser, AST, expander, executor) were written and reasoned through by the authors.


Authors

About

A bash-like shell implemented in C. Features tokenization, AST-based parsing, pipes, redirections, heredocs, environment variable expansion, wildcard globbing, signal handling, and 7 built-in commands.

Topics

Resources

License

Stars

1 star

Watchers

1 watching

Forks

Contributors