AI used to explain this project
Minishell is a system programming project that consists of building a simple Unix shell from scratch.
The goal is to recreate the core behavior of a standard shell such as bash, including command execution, environment variable handling, pipes, and redirections.
Through this project, you gain practical experience with:
- process management
- file descriptor manipulation
- command parsing
- Unix signals
- system calls
By implementing a shell yourself, you gain a deeper understanding of how operating systems execute programs and manage processes.
A shell is a command-line interpreter that allows users to interact with the operating system by entering commands.
Instead of interacting directly with the kernel, users type commands into the shell, which then:
- Parses the command
- Locates the corresponding executable
- Creates a process
- Executes the program
- Returns the result to the user
Shells such as bash, zsh, and sh are essential tools in Unix-based systems and are widely used for system administration, development, and automation.
| Component | Specification |
|---|---|
| Program Name | minishell |
| Language | C |
| Compilation | cc -Wall -Wextra -Werror |
| Authorized Library | libft |
| External Functions | readline, fork, execve, pipe, dup2, waitpid, etc. |
- ✅ Only one global variable allowed (used for signal handling)
- ✅ No memory leaks (except those caused internally by
readline) - ✅ Code must follow the 42 Norm
- ✅ The program must not crash under normal usage
- ❌ No interpretation of unclosed quotes
- ❌ Only features required by the subject are implemented
-
Display a prompt when waiting for user input
-
Maintain a command history
-
Execute binaries using:
- absolute paths
- relative paths
- executables found via
$PATH
-
Proper signal handling
Ctrl + C— interrupt commandCtrl + D— exit shellCtrl + \— ignored
The shell must correctly interpret quotes:
| Quote Type | Behavior |
|---|---|
'single quotes' |
Prevent interpretation of all special characters |
"double quotes" |
Allow $ expansion but prevent other interpretations |
The shell supports the following redirection operators:
| Operator | Description |
|---|---|
< |
Redirect input from a file |
> |
Redirect output to a file |
>> |
Append output to a file |
<< |
Here-document (read input until a delimiter) |
Pipes (|) allow chaining commands by redirecting the output of one command to the input of another.
Example:
ls -l | grep minishell
The shell must expand environment variables using $.
Examples:
echo $HOME
echo $PATH
Special variable:
$?
Expands to the exit status of the last executed command.
The shell implements the following built-in commands:
echo(with-n)cd(with relative or absolute paths)pwdexportunsetenvexit
These commands are executed directly by the shell, without calling external programs.
-
Command execution using
fork() -
Program execution using
execve() -
Process synchronization using:
wait()waitpid()
-
Redirections handled using
dup()anddup2() -
Pipes implemented using
pipe() -
File handling using:
open()close()read()write()
-
Readline library used for command input and history
-
Dynamic memory allocation using:
mallocfree
-
Environment variable handling through
getenv
This project focuses on core concepts in Unix system programming:
- Process creation and control
- File descriptor manipulation
- Signal handling
- Command parsing and tokenization
- Memory management
- Low-level operating system interaction
More implementation details and documentation can be found in the Infor folder.