A comprehensive implementation of a Unix shell written in C, featuring advanced parsing, execution, and shell functionality.
- Minishell
Minishell is a complete shell implementation that replicates the behavior of bash, including command parsing, execution, environment variable management, and advanced shell features. The project demonstrates deep understanding of system programming, process management, and shell internals.
- Interactive shell with custom prompt
- Command execution with proper process management
- Environment variable handling and expansion
- Signal handling (Ctrl+C, Ctrl+D, Ctrl+)
- Exit status management
- Subshell execution with
-coption
- Lexical analysis with tokenization
- Abstract Syntax Tree (AST) construction
- Quote handling (single and double quotes)
- Variable expansion with proper escaping
- Command chaining with
&&and||operators
- Input redirection (
<) - Output redirection (
>,>>) - Here documents (
<<) - Pipes (
|) with multiple pipe support - File descriptor management
- Glob pattern matching (
*) - Directory traversal for wildcard expansion
- Path resolution with absolute and relative paths
- Command history with readline integration
- Alias support with persistent storage
- Custom prompt with user and directory display
- Garbage collection for memory management
- Comprehensive error handling
minishell/
βββ includes/ # Header files
β βββ minishell.h
β βββ includes.h
β βββ error.h
βββ srcs/ # Source code
β βββ main.c # Entry point
β βββ ast/ # Abstract Syntax Tree
β βββ builtins/ # Built-in commands
β βββ exec/ # Command execution
β βββ parsing/ # Lexer and parser
β βββ wildcard/ # Wildcard expansion
β βββ features/ # History, prompt, aliases
β βββ signal/ # Signal handling
β βββ environment/ # Environment management
β βββ garbage_collector/ # Memory management
β βββ utils/ # Utility functions
βββ libft/ # Custom C library
βββ bin/ # Test scripts
βββ Makefile # Build configuration
- GCC compiler
- Make
- Readline library
- Linux/Unix environment
-
Clone the repository
git clone <repository-url> cd minishell
-
Compile the project
make
-
Run minishell
./minishell
make all- Compile the projectmake clean- Remove object filesmake fclean- Remove all generated filesmake re- Rebuild the projectmake leak- Run with Valgrind for memory leak detection
./minishell./minishell -c "echo Hello World"# Basic commands
ls -la
pwd
echo "Hello World"
# Environment variables
export MY_VAR="test"
echo $MY_VAR
# Pipes and redirections
ls -l | grep ".c" > output.txt
cat < input.txt
# Command chaining
ls && echo "Success" || echo "Failed"
# Wildcards
ls *.c
echo /usr/bin/*
# Here documents
cat << EOF
This is a here document
EOF| Command | Description | Example |
|---|---|---|
echo |
Print arguments | echo "Hello World" |
cd |
Change directory | cd /home/user |
pwd |
Print working directory | pwd |
export |
Set environment variables | export VAR=value |
unset |
Unset environment variables | unset VAR |
env |
Print environment variables | env |
exit |
Exit the shell | exit 0 |
alias |
Create command aliases | alias ll="ls -la" |
- Lexical Analysis: Tokenizes input into meaningful units
- Syntax Analysis: Builds Abstract Syntax Tree for command structure
- Error Recovery: Handles syntax errors gracefully
- Process Management: Fork/exec for command execution
- Signal Handling: Proper signal propagation and handling
- File Descriptor Management: Redirection and pipe implementation
- Garbage Collection: Automatic memory cleanup
- Memory Safety: Comprehensive error handling and cleanup
The project includes comprehensive test suites:
./bin/test_basic.sh./bin/test_bonus.sh./bin/test_cd.sh # Directory navigation
./bin/test_echo.sh # Echo command
./bin/test_export.sh # Environment variables
./bin/test_pipes.sh # Pipe functionality./bin/test_valgrind.sh./bin/run_test.sh- Follows 42 coding standards
- Uses custom
libftlibrary - Comprehensive error handling
- Memory leak prevention
make debug # Launch with LLDB debugger
make leak # Run with Valgrind- Modular Design: Separated concerns with clear interfaces
- AST-based Parsing: Robust command structure representation
- Process-based Execution: Proper Unix process management
- Memory Safety: Garbage collection and error handling
- Lexer: Tokenizes shell input
- Parser: Builds command structure
- Executor: Manages process execution
- Builtins: Implements shell commands
- Environment: Manages variables and state
This minishell implementation demonstrates advanced C programming concepts, system programming, and shell internals understanding.