A Unix shell implementation in C, built as part of the 42 curriculum.
This project implements a basic Unix shell with support for command execution, pipes, redirections, environment variable expansion, and built-in commands.
Rather than relying on external libraries, I built three custom dependencies from scratch:
A custom C standard library containing reimplementations of common functions:
- String manipulation (strlen, strcpy, strjoin, split, etc.)
- Memory management (memcpy, memset, calloc, etc.)
- Character classification (isalpha, isdigit, etc.)
- Linked list operations
- Custom printf implementation
- Get next line for reading input
A garbage collector library that handles automatic memory management:
- Memory allocation tracking
- Automatic cleanup on exit
- Prevents memory leaks by maintaining a collection of allocated pointers
- Custom malloc/free wrappers
A data structures library providing:
- Generic linked list implementation
- Function pointers for flexible data handling
- Iterator and mapper functions
- Fork and exec system calls
- Parent-child process relationships
- Process synchronization with wait/waitpid
- Pipe communication between processes
- Standard input/output/error (0, 1, 2)
- File descriptor duplication with dup2
- Pipe file descriptors for inter-process communication
- Handling multiple redirections
- Lexical analysis of command-line input
- Handling quotes (single and double)
- Environment variable expansion
- Heredoc implementation
- Catching and handling SIGINT (Ctrl+C)
- SIGQUIT (Ctrl+) behavior
- Different signal behavior in parent vs child processes
- Tracking all allocations
- Avoiding memory leaks in complex parsing scenarios
- Building a garbage collector to simplify cleanup
make./minishellThe shell supports:
- Command execution from PATH
- Pipes (|)
- Redirections (<, >, <<, >>)
- Environment variables
- Built-ins: echo, cd, pwd, export, unset, env, exit
echo: Print arguments to stdout (supports -n flag)cd: Change directorypwd: Print working directoryexport: Set environment variablesunset: Unset environment variablesenv: Print environment variablesexit: Exit the shell
.
├── main.c # Entry point and main loop
├── include/ # Header files
├── sources/ # Core functionality
│ ├── buildin/ # Built-in command implementations
│ └── utils/ # Helper functions
└── dependencies/ # Custom libraries
├── libft/ # Standard library reimplementation
├── libgc/ # Garbage collector
└── libtrue/ # Data structures