This project has been created as part of the 42 curriculum by phofer, zgahrama.
Minishell is a simplified Unix shell written in C as part of the 42 School curriculum. The objective of the project is to recreate a minimal version of Bash that can interpret and execute user commands in an interactive environment.
The project focuses on understanding how shells work internally, particularly in relation to:
- Process creation (
fork) - Program execution (
execve) - File descriptor management
- Pipes and inter-process communication
- Signal handling
- Environment variable management
The shell displays a prompt, reads commands from the user, parses them, and executes them while supporting core shell features such as pipes, redirections, environment variables, and built-in commands.
Minishell implements the following functionality:
- Interactive prompt
- Command history (via
readline) - Execution of binaries using
PATH - Built-in commands:
echocdpwdexportunsetenvexit
- Pipes (
|) - Redirections
<input redirection>output redirection>>append redirection<<heredoc
- Environment variable expansion (
$VAR) - Exit status expansion (
$?) - Quote handling
- Single quotes
' - Double quotes
"
- Single quotes
- Signal handling
Ctrl+CCtrl+DCtrl+\
The shell aims to behave similarly to Bash for the supported subset of features.
- Logical operators:
&&||
- Parentheses for priority grouping
- Wildcard expansion (
*)
Clone the repository and compile the project using:
makeThis will produce the executable:
minishell
| Rule | Description |
|---|---|
make or make all |
Compile the project |
make clean |
Remove object files |
make fclean |
Remove object files and executable |
make re |
Recompile the project |
The project is compiled using the flags:
-Wall -Wextra -Werror
Start the shell by executing:
./minishellYou will see the shell prompt:
minishell>
Example usage:
minishell> echo Hello World
Hello World
minishell> ls -l | grep .c
minishell> cat file.txt > output.txt
minishell> echo $HOME
/home/userExit the shell using:
exitor by pressing:
Ctrl+D
The project is typically structured into several modules:
Uses the GNU Readline library to display the prompt and manage command history.
The input string is split into tokens such as:
- words
- pipes
- redirections
- operators
Handles:
- environment variables (
$VAR) - exit status (
$?) - quote rules
Tokens are organized into command structures representing pipelines and redirections.
Commands are executed by:
- creating processes (
fork) - setting up pipes (
pipe) - redirecting file descriptors (
dup2) - launching executables (
execve)
Some commands are executed directly by the shell without spawning a new process.
-
42 Minishell Subject
-
Bash Reference Manual https://www.gnu.org/software/bash/manual/
-
POSIX Shell Documentation https://pubs.opengroup.org/onlinepubs/9699919799/
-
Linux man pages https://man7.org/linux/man-pages/
- 42 Minishell Guide https://42-cursus.gitbook.io/guide/3-rank-03/minishell
AI tools were used only as a development aid and learning resource.
AI was used for:
- Explaining low‑level system calls (
fork,execve,dup2,pipe) - Understanding parsing and shell architecture
- Debugging complex issues related to:
- pipes
- heredocs
- signal handling
- Assisting with documentation generation
All generated suggestions were reviewed, tested, and modified where necessary to ensure full understanding and compliance with the 42 project rules.
- phofer
- zgahrama