A minimal shell implementation written in C. Minishell replicates core features of bash, including command execution, pipes, redirections, environment variable expansion, and built-in commands.
- Command Execution – Run external binaries resolved via
$PATH - Pipes – Chain commands with
| - Redirections – Input (
<), output (>), append (>>), and heredoc (<<) - Built-in Commands –
cd,pwd,echo,export,env,unset,exit - Environment Variables –
$VARexpansion and$?for the last exit status - Quote Handling – Single quotes (literal) and double quotes (with expansion)
- Signal Handling –
Ctrl+C,Ctrl+D,Ctrl+\ - Memory Management – Centralized garbage collector to prevent leaks
.
├── main.c # Entry point – read, parse, execute loop
├── Makefile # Build configuration
├── include/
│ └── minishell.h # Type definitions and function declarations
├── parsing/
│ ├── lexer/ # Tokenization of input
│ ├── syntax/ # Syntax validation
│ ├── expansion/ # Environment variable and tilde expansion
│ └── parser/ # Build execution structures from tokens
├── execution/
│ ├── builtins/ # Built-in command implementations
│ ├── executer_core/ # Command execution engine
│ ├── heredoc/ # Heredoc processing
│ └── redirections/ # I/O redirection handling
└── others/
├── MiniLibc/ # Custom C library (strings, ctypes, printf)
├── garbage_collector/ # Memory tracking and cleanup
├── signals.c # Signal handlers
└── envadd.c # Environment variable utilities
- C compiler – GCC or Clang
- GNU Make
- readline library –
libreadline-dev(Debian/Ubuntu) orreadline(macOS via Homebrew)
make # Compile the project
make clean # Remove object files
make fclean # Remove object files and the executable
make re # Full rebuild./minishellOnce running, minishell displays a prompt and accepts commands just like bash:
minishell$ echo "Hello, World!"
Hello, World!
minishell$ ls -la | grep .c | wc -l
1
minishell$ export MY_VAR=42
minishell$ echo $MY_VAR
42
minishell$ exit
- Adil Essadik – aessadik@student.42.fr