A lightweight yet powerful Unix shell designed for simplicity, efficiency, and educational excellence.
Colors were not mandatory, we put them "for the vibe"
Welcome to Minishell – the minimal shell that gets straight to the point. We know most people will only read this introduction, so here’s everything you need to know: Minishell is built to execute commands, handle built-in functions, and support essential piping and redirection features. Inspired by the rigorous requirements of the 42 Ecole Minishell project, it offers an immersive learning experience on Unix internals, while delivering a practical, fully functional shell.
- Features
- Installation
- Usage
- Detailed Functionality and Implementation
- Testing & Development
- Requirements
- Acknowledgments
- Command Execution: Searches and executes external commands via the system’s PATH.
- Built-In Commands: Implements essential built-ins like
cd,echo,exit,env,pwd,export, andunset. - Piping & Redirection: Supports pipes (
|) and redirection operators (<,>,>>,<<) for flexible command chaining and input/output handling. - Signal Handling: Gracefully manages signals such as interrupts (
Ctrl+C) and end-of-file (Ctrl+D) plusCtrl+\to ensure a smooth user experience. - Environment Variable Expansion: Dynamically replaces tokens prefixed with
$to reflect the current environment variables. - Robust Error & Memory Handling: Emphasizes error detection and dynamic memory management to avoid leaks and guarantee stability.
Follow these steps to set up Minishell:
-
Clone the Repository:
git clone https://github.com/denuen/mini_shell.git cd mini_shell -
Compile the Source:
make
Note: Ensure you have
gcc(or a compatible C compiler) and GNU Make installed. -
Run Minishell:
./mini_shell
Interact with Minishell just as you would with any standard Unix shell:
- Execute Commands: Type any command and press Enter.
- Built-In Functions: Use commands like
cd,echo,exit, andenvfor built-in tasks. - Redirection & Piping: Utilize operators such as
>(output redirection),<(input redirection), and|(command piping) to streamline your workflow. - Help: Type
helpinside the shell to display available commands and usage information.
Minishell is more than a basic command interpreter—it is a comprehensive educational project designed to meet the strict criteria of the 42 curriculum. Below is an in-depth breakdown of its functionality and implementation:
- Input Handling: Reads user input character by character to manage whitespace, quotes, and special symbols.
- Quotation Support: Processes both single (
' ') and double (" ") quotes to ensure correct interpretation of compound commands and arguments. - Tokenization: Breaks down the input into meaningful tokens (commands, arguments, operators) for subsequent processing.
- Built-In Implementation: Offers core commands like:
cdfor directory navigation,echofor text display,exitfor terminating the shell,envfor environment variable listing.
- Dynamic Environment Variables: Replaces
$VARIABLEtokens with values from the current environment, enabling dynamic command contexts.
- Forking Processes: Uses
fork()to create child processes for executing non-built-in commands. - Command Execution: Utilizes
execve()within child processes, searching for the command executable via the system’s PATH. - Process Synchronization: The parent process employs
waitpid()to synchronize and retrieve the exit statuses of child processes.
- Piping: Implements inter-process communication by linking the standard output of one process directly to the standard input of another.
- Redirection Mechanics:
- Input Redirection (
<): Reads input from specified files. - Output Redirection (
>): Writes or overwrites output to files. - Append Redirection (
>>): Appends output to existing files. - Heredoc (
<<): Supports multi-line input until a designated delimiter is encountered.
- Input Redirection (
- Error Handling: Provides user-friendly error messages for incorrect usage of redirection and piping.
- Signal Handling: Catches interrupts (e.g.,
Ctrl+C) and handles EOF scenarios (e.g.,Ctrl+D) without crashing the shell. - Memory Management: Carefully manages dynamic memory to prevent leaks, a critical aspect of robust Unix system programming.
- Error Reporting: Displays meaningful error messages for both command and system call failures, ensuring clear communication with the user.
- Learning Focus: Every aspect of Minishell—from process creation to memory management—is designed to teach real-world Unix programming principles.
- Strict Adherence: The project strictly adheres to the guidelines provided by the 42 curriculum, offering hands-on experience in building a fully functional shell.
- Automated Tests: While not mandatory, adding unit tests and integration tests is highly recommended to catch potential issues early. Consider using frameworks like CUnit for testing C programs.
- Debugging: Use tools such as
gdbfor debugging and valgrind to detect memory leaks, ensuring that Minishell performs reliably under various conditions. - Continuous Integration: For advanced setups, integrate CI/CD pipelines (e.g., GitHub Actions) to automatically build and test the project on new commits.
- System: Unix or Linux environment.
- Compiler:
gcc(or a similar C compiler). - Build Tool: GNU Make.
- Standards Compliance: The code should adhere to the Norme, as stipulated by the 42 school guidelines.
If you encounter any issues or have improvement suggestions, please open an issue on the repository.
- Community: Thanks to the active developer community and all 42 students whose shared experiences and resources have shaped this project.
- 42 Ecole: Special recognition to Ecole 42 for fostering an environment of innovation and rigorous learning.
- Contributors: apintaur (denuen) & ahabdelr (ahmeee-dev)
Enjoy using Minishell, and happy coding!
