Skip to content

Latest commit

Β 

History

History
125 lines (94 loc) Β· 4.78 KB

File metadata and controls

125 lines (94 loc) Β· 4.78 KB

Minishell

Language Score Status 42


Project Overview

The Minishell project from 42 School introduces:

  • The fundamentals of shell programming
  • Process creation, pipes, and redirections
  • Handling signals, environment variables, and built-in commands

This project is all about recreating a simplified version of the Bash shell β€”
learning how a real shell parses commands, executes processes, and manages the environment 🐚


πŸ“š Learning Goals

  • Master process control with fork, execve, and wait
  • Implement I/O redirections and pipes
  • Manage signals like ctrl+C, ctrl+D, and ctrl+\
  • Handle environment variables dynamically
  • Build a modular, robust, and readable C program

🧠 Design Choices

The project is structured with a clear separation between parsing and execution.

  • Parsing is responsible for:

    • Tokenizing user input
    • Handling quotes
    • Expanding environment variables
    • Building clean command structures
  • Execution only works with already parsed and expanded commands.

This design avoids mixing string manipulation logic with process control, making the code easier to debug, extend, and reason about.


🧩 Work Distribution

Fabio Vitharana Role

  • Parsing layer implementation
  • Tokenization and syntax analysis
  • Quote handling and variable expansion
  • Built-in command logic

Ilaria Nassi Role

  • Execution layer implementation
  • Process creation and management
  • Pipes and redirections handling
  • Signal handling and exit status management

πŸ—οΈ Architecture Overview

Below is a simplified view of how Minishell processes a command:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚               User Input                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚               Parsing Layer              β”‚
β”‚  β€’ Tokenization                          β”‚
β”‚  β€’ Syntax checking                       β”‚
β”‚  β€’ Environment variable expansion         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Execution Layer             β”‚
β”‚  β€’ Handle built-ins                      β”‚
β”‚  β€’ Set up pipes and redirections         β”‚
β”‚  β€’ Create processes with fork/execve     β”‚
β”‚  β€’ Wait for children and manage status   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Shell Loop                  β”‚
β”‚  β€’ Display prompt                        β”‚
β”‚  β€’ Handle signals                        β”‚
β”‚  β€’ Repeat until exit                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ” Expansion Behavior

Environment variable expansion is handled during the parsing phase, before command execution.

  • Variables are expanded using $VAR
  • $? expands to the last command exit status
  • No expansion occurs inside single quotes
  • Expansion is allowed inside double quotes
  • Heredoc delimiters are not expanded

By resolving expansions early, the execution layer only deals with final strings.

πŸ‘©β€πŸ’» Authors


πŸ“„ License

This project is for educational purposes only and is part of the 42 Common Core curriculum. 42 Common Core curriculum,