A 42 project focused on building a minimal Unix shell. The goal is to reproduce core shell behavior: parsing, quoting rules, redirections, pipelines, environment handling, builtins, and correct signal behavior in interactive mode.
- This minishell implements:
- Interactive prompt using GNU Readline
- Tokenization + parsing into an AST
- Execution of builtins and external commands
- Pipelines (
|) and redirections (<,>,>>) - Heredoc (
<<) with properCtrl+Cbehavior - Environment variables (
$VAR,$?) and expansion rules - Correct signal handling similar to
bash(parent vs child processes)
cdecho(with-n)envexitexportpwdunset
- Pipes:
cmd1 | cmd2 | cmd3 - Redirections:
- input:
< file - output:
> file - append:
>> file
- input:
- Heredoc:
cmd << DELIMITER- stops on delimiter
Ctrl+Caborts heredoc and returns to prompt
$VAR$?(last exit status)- Expansion inside double quotes, no expansion inside single quotes
- Parent shell:
Ctrl+Cprints newline and shows a fresh promptCtrl+\ignored
- Child processes:
- default signal behavior (so
Ctrl+C/Ctrl+\affect running commands normally)
- default signal behavior (so
- Heredoc:
Ctrl+Caborts heredoc collection and sets status to130
├── docs/ # Project documentation
├── include/ # Public header
├── libft/ # Custom Libft library
├── src/
│ ├── builtins/ # Builtin command implementations
│ ├── env/ # Environment handlin
│ ├── executor/ # Command execution: AST execution, pipes, redirections, heredoc
│ ├── parser/ # Lexing, parsing, tokenization, expansion
│ ├── utils/ # Cleanup, signal handlers
│ └── main.c # Program entry point + main interactive loop (readline → parse → execute)
├── readline.supp # Valgrind suppression file for GNU Readline-related “leaks”
└── Makefile # Build rules
Uses readline() for interactive input and history support.
Splits the input into tokens while respecting quotes and operators.
Expands environment variables and $? (exit status).
Builds an AST / execution structure (commands, pipes, redirections).
- Collects heredocs before execution
- Runs builtins in the parent when needed (e.g.,
cd,exit) - Forks and executes external commands
- Handles pipe chains and redirections
make # builds minishell
make clean # removes object files
make fclean # removes binaries and objects
make re # rebuilds everything./minishellminishell$ echo hello
hello
minishell$ export NAME=Martin
minishell$ echo $NAME
Martin
minishell$ ls -l | grep minishell
...
minishell$ cat < infile | wc -l > out.txtminishell$ cat << EOF
> hello
> world
> EOF
hello
world- This project targets the mandatory minishell requirements from 42.
- Only required shell grammar and behaviors are implemented (not a full bash clone).
- Behavior may differ from bash in edge cases not required by the subject.
This project includes two Makefile targets for running Valgrind with a readline suppression file:
make valgrindRuns Valgrind with leak checking:
valgrind --leak-check=full --track-origins=yes --suppressions=readline.supp ./minishellmake logRuns Valgrind and writes output into valgrind.log:
valgrind --leak-check=full --log-file=valgrind.log --track-origins=yes \
--show-leak-kinds=all --suppressions=readline.supp ./minishellNote: if you press Ctrl+C while running minishell through make log, GNU make may display Interrupt. This happens because Ctrl+C is delivered to the whole foreground job (make + valgrind + minishell). For signal testing, running Valgrind directly is recommended.
Created and maintained by Martin Justa and Diana Kolarova as part of the 42 school curriculum.