A comprehensive Unix shell implementation recreating bash functionality
Features β’ Installation β’ Usage β’ Built-ins β’ Architecture
- About
- Features
- Installation
- Usage
- Built-in Commands
- Advanced Features
- Architecture
- Project Structure
- Memory Management
- Signal Handling
- Testing
- Authors
- License
Minishell is a simplified shell implementation written in C as part of the 42 School curriculum. This project recreates the core functionality of bash, providing users with a command-line interface capable of executing commands, managing processes, handling I/O redirection, and implementing essential built-in commands.
The shell handles complex parsing, process management, signal handling, and memory management while maintaining compatibility with standard Unix shell behavior.
- π Interactive Command Execution - Execute system commands and built-ins
- π Command History - Navigate through command history using arrow keys
- π¨ Colored Prompt - Beautiful, informative prompt with color coding
- π Path Resolution - Automatic command path discovery
- π§ Memory Safe - Comprehensive memory management with no leaks
- π Quote Handling - Support for single (
') and double (") quotes - π Pipe Operations - Chain commands with pipes (
|) - π Variable Expansion - Environment variable substitution (
$VAR) - π« Syntax Validation - Comprehensive input validation and error handling
- π₯ Input Redirection (
<) - Redirect stdin from files - π€ Output Redirection (
>) - Redirect stdout to files - π Append Mode (
>>) - Append output to files - π Here Documents (
<<) - Multi-line input with delimiters
- π Pipeline Execution - Multi-command pipelines
- β‘ Signal Handling - Proper
SIGINTandSIGQUITmanagement - π― Exit Status - Accurate exit code handling
- π§΅ Fork Management - Efficient process creation and cleanup
# Ubuntu/Debian
sudo apt-get update
sudo apt-get install build-essential libreadline-dev
# macOS
brew install readline# Clone the repository
git clone [repository-url]
cd Babuterm
# Compile the project
make
# Run the shell
./minishellmake # Build the project
make clean # Remove object files
make fclean # Remove object files and executable
make re # Rebuild everything# Start the shell
./minishell
# Execute commands
babuterm$ ls -la
babuterm$ echo "Hello, World!"
babuterm$ cat file.txt# Chain commands with pipes
babuterm$ ls -la | grep ".c" | wc -l
babuterm$ cat file.txt | head -10 | tail -5# Input redirection
babuterm$ wc -l < input.txt
# Output redirection
babuterm$ echo "Hello" > output.txt
babuterm$ ls -la >> log.txt
# Here documents
babuterm$ cat << EOF
This is a multi-line
input example
EOF# Environment variables
babuterm$ echo $HOME
babuterm$ echo "User: $USER"
babuterm$ echo 'Literal: $HOME' # No expansion in single quotes| Command | Description | Example |
|---|---|---|
echo |
Display text with optional -n flag |
echo -n "Hello World" |
cd |
Change directory | cd /path/to/directory |
pwd |
Print working directory | pwd |
export |
Set environment variables | export VAR=value |
unset |
Remove environment variables | unset VAR |
env |
Display environment variables | env |
exit |
Exit the shell | exit [code] |
babuterm$ echo "Hello World" # Basic output
babuterm$ echo -n "No newline" # Suppress newline
babuterm$ echo -n -n -n "Multiple -n" # Multiple -n flagsbabuterm$ cd /home/user # Absolute path
babuterm$ cd .. # Parent directory
babuterm$ cd # Home directory
babuterm$ cd - # Previous directorybabuterm$ export NAME=value # Set variable
babuterm$ export PATH=$PATH:/new/path # Modify PATH
babuterm$ export # List all exported variables- Single Quotes: Preserve literal values
- Double Quotes: Allow variable expansion
- Quote Removal: Automatic quote stripping in arguments
- Comprehensive syntax error detection
- Graceful handling of invalid commands
- Proper exit status propagation
- Memory cleanup on errors
Ctrl+C(SIGINT): Interrupt current commandCtrl+\(SIGQUIT): Ignored in interactive modeCtrl+D(EOF): Exit shell gracefully
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Input Parser βββββΆβ Command Parser βββββΆβ Executor β
β (Lexical) β β (Syntax) β β (Execution) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Quote Handler β β Variable Expand β β Process Manager β
β Error Validator β β Path Resolution β β Signal Handler β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
typedef struct s_command {
int is_correct; // Validation flag
char **args; // Command arguments
char *cmd_cpt; // Command name
char *path; // Command path
char *inredir; // Input redirection
char **delimiters; // Here-doc delimiters
char **outredirs; // Output redirections
int appd_out; // Append flag
int error; // Error status
} t_command;typedef struct s_list_envp {
char *envp_content; // Environment variable
struct s_list_envp *next; // Next node
} t_list_env;Babuterm/
βββ π Makefile # Build configuration
βββ π minishell.h # Main header file
βββ π structs.h # Data structures
βββ π src/ # Source code
β βββ π main.c # Entry point
β βββ π minishell.c # Core shell logic
β βββ π builtin/ # Built-in commands
β β βββ π ft_echo.c # Echo implementation
β β βββ π ft_cd.c # CD implementation
β β βββ π ft_export.c # Export implementation
β β βββ π ... # Other built-ins
β βββ π parsing/ # Input parsing
β β βββ π parse_commands.c
β β βββ π ...
β βββ π commands/ # Command execution
β βββ π redirection/ # I/O redirection
β βββ π signals/ # Signal handling
β βββ π utils/ # Utility functions
β βββ π errors/ # Error handling
βββ π libft/ # Custom C library
β βββ π libft.h
β βββ π ft_*.c # Library functions
β βββ π get_next_line/ # GNL implementation
βββ π obj/ # Compiled objects
- Automatic Cleanup: All allocated memory is properly freed
- Error Handling: Memory cleanup on all error paths
- Leak Prevention: Comprehensive testing for memory leaks
- Resource Management: Proper file descriptor and process cleanup
# Test for memory leaks
valgrind --leak-check=full --track-origins=yes ./minishell
# Test with specific commands
echo "command" | valgrind ./minishell- SIGINT (
Ctrl+C): Display new prompt - SIGQUIT (
Ctrl+\): Ignored - EOF (
Ctrl+D): Exit shell
- SIGINT: Interrupt running command
- SIGQUIT: Send quit signal to command
- Child Processes: Proper signal propagation
# Basic functionality
echo "test" | ./minishell
echo "ls | wc -l" | ./minishell
echo "export TEST=value && echo \$TEST" | ./minishell
# Edge cases
echo "ls |" | ./minishell # Syntax error
echo "echo \"unclosed quote" | ./minishell # Quote error# Create test suite
bash test_suite.sh
# Compare with bash
echo "command" | bash > expected.txt
echo "command" | ./minishell > result.txt
diff expected.txt result.txt| Author | GitHub | |
|---|---|---|
| manufern | @manufern | manufern@student.42.fr |
| cfeliz-r | @cfeliz-r | cfeliz-r@student.42.fr |
- Lines of Code: ~2,750
- Files: 45+ source files
- Functions: 100+ custom functions
- Development Time: 3+ months
- Language: C (C99 standard)
While this is an educational project, contributions and suggestions are welcome:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is part of the 42 School curriculum. It's shared for educational purposes.
Made with β€οΈ at 42 Madrid
"The shell is the ultimate power tool"