Welcome to Minishell! This project is part of the 42 school curriculum and challenges students to implement a Unix-like shell from scratch in C. This shell supports many features of real-world shells, such as parsing and executing commands, handling input/output redirection, and managing processes.
The Minishell project is a fantastic opportunity to dive into system-level programming, understand process management, and improve C programming skills. Here’s a look at the key achievements and features that this implementation brings to the table.
Minishell is a simplified shell designed to mimic the behavior of common Unix shells, such as Bash. It was developed as part of the 42 school curriculum to deepen understanding of command-line interfaces and core shell functionality. The project is a blend of low-level programming, process handling, and Unix system calls.
- Recreate a simple command-line interpreter with features like command parsing, process management, and signal handling.
- Handle complex user inputs, implement redirections, pipelines, and manage child processes.
- Gain hands-on experience with C programming in a system-level environment.
This implementation of Minishell includes the following features:
-
Command Parsing
- Supports complex command parsing including pipes
|, redirections>,<, and>>. - Handles multiple commands on a single line separated by semicolons
;.
- Supports complex command parsing including pipes
-
Builtin Commands
- Implements several built-in commands, such as
echo,cd,pwd,export,unset,env, andexit, with behavior mimicking that of standard shells.
- Implements several built-in commands, such as
-
Environment Variable Management
- Supports setting, updating, and retrieving environment variables.
- Integrates variables directly into commands and parsing to ensure smooth user interaction.
-
Error Handling
- Implements robust error handling for invalid commands, incorrect syntax, and undefined behavior.
- Provides informative error messages similar to those found in a Unix shell.
-
Signal Management
- Responds to
SIGINT(Ctrl+C),SIGQUIT, andSIGTSTPsignals. - Ensures safe handling and termination of processes when signals are sent.
- Responds to
-
Pipelines and Redirections
- Enables piping output from one command to another (
ls | grep minishell). - Implements input and output redirections, including
>,<, and>>for files.
- Enables piping output from one command to another (
To install Minishell, clone the repository and compile the source code:
git clone https://github.com/OkuM1/minishell.git
cd minishell
makeThis will create an executable named minishell in the project directory.
Once compiled, start Minishell by running the following command:
./minishellThe shell supports both built-in and external commands and many more features. Here are a few examples:
minishell$ echo Hello, Minishell!
minishell$ pwd
minishell$ ls | grep minishell
minishell$ export PATH=/new/path:$PATH
minishell$ exitDuring the development of Minishell, several technical challenges were overcome to implement a fully functional shell environment. Here are the main achievements:
- Advanced Command Parsing: Implemented a custom parser to handle complex command structures involving pipelines and redirections, ensuring compatibility with Unix-like syntax.
- Process and Signal Management: Learned to manage processes effectively, handling background and foreground processes with real-time signal handling for a seamless user experience.
- Robust Error Management: Built custom error messages and handling routines to provide clear feedback, closely resembling the error responses of actual Unix shells.
- System-Level Programming Expertise: Gained in-depth understanding of system calls, particularly in areas of process management, file I/O, and inter-process communication.
- Optimized Resource Usage: Employed efficient memory management practices, ensuring minimal memory leaks and optimal resource usage even with heavy command sequences.
- Enhanced Shell Features: Implemented user-friendly shell features like environment variable expansion and built-in command support for enhanced usability.
Distributed under the MIT License. See LICENSE for more information.