A minimal shell implementation written in C as part of the 42 School curriculum. This project recreates the functionality of bash, including command parsing, execution, built-in commands, and pipeline handling.
cd- Change directorypwd- Print working directoryecho- Print arguments with optionsenv- Display environment variablesexport- Set environment variablesunset- Unset environment variablesexit- Exit the shell
- Pipeline Support - Execute multiple commands with pipes (
|) - Redirection - Input/output redirection (
<,>,>>) - Here Document - Handle
<<redirection - Environment Variables - Full environment variable management
- Signal Handling - Proper handling of SIGINT, SIGQUIT, and other signals
- Quote Handling - Support for single and double quotes
- Command History - Using readline library for command history
minishell/
├── includes/
│ ├── libft.h # Libft library header
│ └── minishell.h # Main project header
├── Libft/ # Custom C library (42's libft)
├── srcs/
│ ├── builtin/ # Built-in command implementations
│ ├── execute/ # Command execution logic
│ ├── free/ # Memory management
│ ├── main/ # Main program entry point
│ ├── parse/ # Command parsing and tokenization
│ ├── signal/ # Signal handling
│ └── utility/ # Utility functions
├── Makefile
└── README.md
- GCC compiler
- Make
- Readline library (for command history and line editing)
Rewrite your gnu readline library path in the Makefile
- common path ->
/usr/local/lib,/usr/local/include - if you can't find readline library,
yum install readline-devel
READ_INC_FG = -I/usr/include/readline
READ_LIB_FG = -L/usr/include/readline
makemake clean # Remove object files
make fclean # Remove object files and executable
make re # Clean and rebuild./minishellOnce running, you can use the shell like any other Unix shell:
Minishell > ls -la
Minishell > echo "Hello World"
Minishell > cd /path/to/directory
Minishell > export MY_VAR="value"
Minishell > env | grep MY_VAR
Minishell > ls | grep .c | wc -l
Minishell > cat < input.txt > output.txt
Minishell > exit- Tokenizes input into commands and arguments
- Handles quotes (single and double) properly
- Supports environment variable expansion
- Validates syntax for pipes and redirections
- Fork-based process execution
- Pipeline implementation with proper file descriptor management
- Built-in command detection and execution
- External command execution via
execve
- Careful memory allocation and deallocation
- Prevention of memory leaks
- Proper cleanup of resources
- Handles Ctrl+C (SIGINT) and Ctrl+\ (SIGQUIT)
- Different behavior for main process vs child processes
- Proper signal handling during pipeline execution
- Language: C
- Standards: C99
- Libraries: libft (custom), readline
- Architecture: Unix-like shell implementation
- Memory Management: Manual memory management with malloc/free
The shell provides comprehensive error handling for:
- Invalid syntax
- Command not found
- Permission denied
- File not found
- Memory allocation failures
- Signal interruptions
This is a minimal shell implementation and does not include:
- Advanced scripting features
- Job control
- Advanced globbing patterns
- Some advanced redirection features
This project was developed as part of the 42 School curriculum by:
- hyeonkki
- kyunkim
This project is part of the 42 School curriculum and follows the school's guidelines and restrictions.