This project has been created as part of the 42 curriculum by bddkalle.
Minishell is a small, simplified shell implementation aiming to reproduce the behavior of a UNIX shell interpreter as realistically as possible. The project covers tokenizing, parsing, pipelines (pipes), redirections (including heredoc), builtin commands, environment handling and basic signal management. Minishell was developed as part of the 42 curriculum and is intended to provide deep, hands-on understanding of process control, file descriptors, signals and shell parsing.
- Basic Bash-compatible input parsing and syntax.
- Pipes:
cmd1 | cmd2 | cmd3. - Redirections:
- Output:
>and>> - Input:
< - Heredoc:
<<
- Output:
- Environment variable expansion using
$VAR. - Builtins (executed without forking):
cd,echo,pwd,export,unset,env,exit. - Signal handling comparable to interactive Bash (
SIGINT/Ctrl-C behavior, ignoringSIGQUITin interactive mode, etc.). - Error handling for syntax errors, command-not-found, access/permission errors.
- Command execution pipeline implemented with
fork,execve,dup2, andpipe.
IMPORTANT: This project depends on
libftas a Git submodule. Clone with submodules to ensurelibftis present.
- Clone the repository (with submodules):
git clone --recurse-submodules https://github.com/bddkalle/minishell.git
cd minishellIf you already cloned without submodules, fetch them afterwards:
git submodule update --init --recursive- Compile the project:
makeThis produces the minishell binary in the repository root.
- Run the shell:
./minishellExample commands to try inside the shell:
echo "Hello World"
ls -l | grep minishell
export TEST=42
echo $TEST
cat < input.txt | grep foo > out.txtminishell/
├── src/
│ ├── lexer/ # Tokenizing input → tokens
│ ├── parser/ # Build AST, check syntax
│ ├── exec/ # Pipelines, redirections, FD management
│ ├── builtins/ # cd, echo, export, ...
│ ├── env/ # Environment management
│ └── signals/ # Signal handlers (interactive behavior)
├── libft/ # Submodule – utility functions
├── includes/ # Headers (data structures, APIs)
├── Makefile
└── minishell.c
- Tokenizer: Splits the input string into meaningful tokens (words, pipes, redirections, quotes).
- Parser / AST: Builds an internal representation of the command chain, validates syntax and prepares execution structures.
- Executor: Constructs the pipeline, creates child processes, duplicates file descriptors (
dup2), opens redirections and invokesexecve(). - Builtins without fork: Certain builtins must run in the parent process so they can change the environment (e.g.
cd,export). - Signals: Adjusted behavior for interactive mode to match common shell expectations.
- Build a debug binary with additional logging:
make debug
./minishell- Memory leak checks on macOS:
leaks --atExit -- ./minishell- Memory leak checks on Linux (e.g. WSL):
valgrind --leak-check=full ./minishell- For behavioral comparison, test against Bash for various use cases.
- Do not use
system(). - Correct handling of signals (
SIGINT,SIGQUIT). - Correct exit statuses.
- Proper handling of single and double quotes.
- Correct pipe handling.
- Correct redirection handling (>, >>, <, <<).
- Implement builtins and
$?expansion. - Leak-free implementation.
Classic references and documentation useful for this project:
- POSIX and Shell specifications (man pages:
sh,bash,execve(2),dup2(2),pipe(2)). - The GNU Bash Reference Manual — for expected interactive behavior and conventions.
Advanced Programming in the UNIX Environment(Stevens) — chapters on processes and I/O.- Valgrind documentation — for memory leak detection.
- Tutorials and articles on shell parsing, tokenization and implementing toy shells.
- This README was translated and edited using an AI assistant to produce a clear English version and to ensure the README meets the 42 README requirements. The AI was used only for the README text (translation, restructuring, and wording). No project source code was generated or modified by AI — the implementation and logic remain the author's work.
This project follows the licensing terms of the 42 curriculum. Optionally, an open-source license (e.g. MIT) may be added by the author.
Felix Steinmann — GitHub: https://github.com/bddkalle