This project has been created as part of the 42 curriculum by narginaa, aarab.
Minishell is a core project in the 42 curriculum where the goal is to create a simple UNIX command interpreter heavily inspired by Bash.
The primary objective of this project is to dive deep into system architecture, process creation, file descriptors, and signals. By rebuilding a shell from scratch in C, we learn how an operating system reads user input, parses commands, manages the environment, and connects standard inputs and outputs via pipes and redirections.
Key Features Implemented:
- Displaying a prompt and reading user input using the
readlinelibrary. - Maintaining command history.
- Searching and launching the right executable (based on the
PATHvariable or using relative/absolute paths). - Implementing core built-in commands:
echo(with-n),cd,pwd,export,unset,env, andexit. - Handling pipes (
|) to connect the output of one command to the input of the next. - Handling file redirections:
<(input),>(output truncate),>>(output append), and<<(heredoc). - Expanding environment variables (
$VAR) and the exit status ($?). - Interpreting unclosed single (
') and double (") quotes properly. - Handling core signals like
Ctrl+C,Ctrl+D, andCtrl+\.
Prerequisites
To build and run this project, you will need a C compiler (cc, gcc, or clang), make, and the readline library installed on your system.
Compilation
Clone the repository and compile the project by running make at the root of the directory:
makeThis will compile the source files and generate the minishell executable. You can also use make clean to remove object files, make fclean to remove object files and the executable, and make re to recompile from scratch.
Execution Start the interactive shell by running:
./minishellOnce the prompt appears, you can type commands just as you would in a standard UNIX terminal. To exit the shell, type exit or press Ctrl+D.
References & Documentation
- Bash Reference Manual - To understand the exact expected behavior of commands, quotes, and expansions.
- GNU Readline Library Documentation
- Linux Manual Pages (
man) for system calls:fork,execve,pipe,dup2,waitpid,signal,sigaction,stat. - Tutorials on Abstract Syntax Trees (AST) and Lexer/Parser architecture in C.
AI Usage During the development of this project, Artificial Intelligence (LLM) was utilized as an interactive tutor and debugging assistant. Specifically, AI was used for:
- Architectural Planning: Discussing the correct chronological order of operations (Lexer -> Expander -> Parser -> Executor) to properly handle Bash's word-splitting and AST generation, as well as resolving architectural clashes when merging the parsing and execution codebases.
- Memory Management & Valgrind: Analyzing complex Valgrind output logs to pinpoint the exact locations of
Invalid free()crashes, dangling pointers, and memory leaks specifically related to the environment variable array and dynamic string building. - Syntax and Logic Review: Identifying C-language logic inversions (e.g., incorrect
ft_strcmpconditions) and boundary calculation errors during string splitting. No direct code was copy-pasted blindly; AI was strictly used to explain why a bug was occurring so a fix could be implemented manually.