A simplified Unix shell implementation built as part of the 42 school curriculum.
Minishell supports basic shell functionalities including command execution, redirections, pipelines, environment variables, and more — all written in C, following strict 42 Norminette standards.
| Category | Implemented |
|---|---|
| Builtins | cd, echo -n, env, export, pwd, unset, exit (with status codes) |
| Redirections | <, >, >>, heredoc (<<) with variable expansion suppression |
| Pipes | ` |
| Variables | $VAR, $? (exit status), SHLVL (shell level tracking) |
| Quotes | Full handling of ' ', " ", nested quotes, and edge cases ("''", '""') |
| Signals | Ctrl+C (SIGINT), Ctrl+\ (SIGQUIT), Ctrl+D (EOF) |
.
├── src/ # Main source code
│ ├── lexing/ # Tokenization of input
│ ├── parser/ # Building command structures
│ ├── executing/ # Command execution and pipes
│ ├── builtins/ # Built-in command functions
│ ├── functions/ # Utility functions
│ ├── cleaner/ # Setup the environment
│ ├── inc/ # Header files
│ └── signals/ # Handles signals
├── Makefile # Build system
├── Main.c # Entry point
└── README.md- Input: Displays a prompt and reads user input using
readline(supports history navigation). - Lexing: Splits input into tokens while handling:
- Quotes (
'...',"...") and escapes (\). - Environment variables (
$VAR). - Metacharacters (
|,>,<, etc.).
- Quotes (
- Parsing:
- Creates a token list from lexed input.
- Merges tokens into commands by splitting on metacharacters (e.g.,
ls -l | grep test→ 2 commands). - Builds an executable structure (AST) with redirections/pipes.
- Execution:
- Runs builtins directly (e.g.,
cd,export). - Executes external binaries via
PATH(e.g.,/bin/ls). - Handles pipes/redirections with
dup2andfork.
- Runs builtins directly (e.g.,
- Cleanup: Frees memory, resets file descriptors, waits for next input.
- Logical operators (
||,&&) - Job control (
fg,bg, etc.) - File descriptor aggregation (
2>&1, etc.)
sudo apt update
sudo apt install libreadline-dev
makeTo clean build artifacts:
make clean # removes object files
make fclean # removes object files and binary
make re # rebuilds everything./minishellOnce launched, you can start typing commands like:
> echo Hello World
> ls -la | grep Minishell
> export var=test
> cat << EOF
heredoc content
EOFThis project was developed as part of the 42 school curriculum by:
Do not use this for cheating in the 42 program.