This repository contains my implementation of the minishell project, developed as part of the 42 School curriculum. The goal is to build a small, POSIX‑like command‑line shell in C, gaining hands‑on experience with processes, file descriptors, signals, and terminal handling.
Note: This shell is for educational purposes only. It is not intended to replace a production shell.
- Overview
- Common Instructions
- Mandatory Part
- Bonus Part
- Project Structure
- Installation
- Usage
- Error Handling
- Acknowledgments
- Disclaimer
- License
minishell implements a subset of Bash features:
- Interactive prompt with command history
- Parsing of simple commands, quotes, and environment‑variable expansions
- I/O redirections (
<,>,>>,<<) - Pipelines (
|) - Built‑in commands:
echo,cd,pwd,export,unset,env,exit - Signal handling:
Ctrl‑C,Ctrl‑D,Ctrl‑\
The project uses the GNU Readline library for line editing and history management.
- Language & Norm: Write in C, strictly following the 42 Norm. Norm errors in either mandatory or bonus code yield zero.
- Memory: No leaks in your own code. Readline leaks are acceptable.
- Makefile: Must compile with
cc -Wall -Wextra -Werrorand include rules:NAME,all,clean,fclean,re. Avoid unnecessary relinking. - Allowed Functions:
- Readline APIs:
readline,add_history,rl_* - Process & I/O:
fork,execve,wait,pipe,dup2,open,read,write,close, … - Signals & Terminal:
signal,sigaction,kill,tcgetattr,tcsetattr,ioctl, … - Utilities:
getcwd,chdir,stat,opendir,readdir,getenv,exit,perror,strerror,printf,malloc,free
- Readline APIs:
- Libft: You may include your own libft in a
libft/folder; compile it via your Makefile.
- Display a prompt each time (
minishell$, for example). - Maintain a history of commands via Readline; pressing up/down navigates history.
- Exit cleanly on
Ctrl‑D.
- Tokenize input respecting single and double quotes:
- Single quotes prevent interpretation of all special characters.
- Double quotes prevent interpretation except for
$(variable expansion).
- Split commands and their arguments correctly.
- Search executables in
$PATHor execute via absolute/relative path.
Implement the following built‑ins internally (no execve):
echo [-n] [args...]cd [directory]pwdexport [KEY[=VALUE] ...]unset KEY ...envexit [n]
- Redirections:
< file— redirect stdin> file— redirect stdout (truncate)>> file— redirect stdout (append)<< DELIM— here‑document (read until line equalsDELIM)
- Pipelines: Connect multiple commands with
|.
- Expand
$VARto its environment value. - Expand
$?to the last foreground pipeline's exit status. - Maintain and modify the environment for
export/unset.
- Use one global
volatile sig_atomic_tvariable to store the last received signal number—no other globals. - Interactive mode:
Ctrl‑Cprints a new prompt on a fresh line.Ctrl‑Dexits the shell.Ctrl‑\is ignored.
- Child processes should inherit default signal behaviors.
Implement perfectly (mandatory must be flawless first):
- Command chaining:
&&,||with correct precedence and parentheses. - Globbing: Support
*wildcards for filename expansion in the current directory.
minishell/
├── includes/ # minishell.h, parser.h, exec.h, etc.
├── srcs/ # main.c, parser/*.c, exec/*.c, builtins/*.c, signals/*.c
├── libft/ # (optional) your libft and its Makefile
├── Makefile # rules: NAME, all, clean, fclean, re (and bonus if used)
├── .gitignore
└── README.md # this file
-
Clone the Repository:
git clone https://github.com/marco-ht/minishell.git cd minishell -
Build the Project:
Use the provided Makefile to compile your source files:
make
This command will produce the executable named
minishell.
Run the shell:
./minishell- Type commands as in Bash.
- Use
<,>,>>,<<, and|as described. - Use built‑ins without forking.
- Press
Ctrl‑Dor enterexitto quit.
- Syntax errors (unclosed quotes, misplaced pipes/redirections) should print
syntax error…and return a non‑zero status. - Command not found prints
minishell: command: not found. - Redirection failures print the appropriate
perrormessage. - Fatal errors exit with a non‑zero status and free all allocated resources.
- Thanks to the 42 community, mentors, and fellow students for their guidance and support.
- Inspired by the Bash manual and GNU Readline documentation.
IMPORTANT: This project was developed solely as part of the educational curriculum at 42 School. The code in this repository is published only for demonstration purposes to showcase my programming and system-level development skills.
Academic Integrity Notice: It is strictly prohibited to copy or present this code as your own work in any academic submissions at 42 School. Any misuse or uncredited use of this project will be considered a violation of 42 School's academic policies.
This repository is licensed under the Creative Commons - NonCommercial-NoDerivatives (CC BY-NC-ND 4.0) license. You are free to share this repository as long as you:
- Provide appropriate credit.
- Do not use it for commercial purposes.
- Do not modify, transform, or build upon the material.
For further details, please refer to the CC BY-NC-ND 4.0 license documentation.
Developed with dedication and in strict adherence to the high standards of 42 School.