Skip to content

migclay12/minishell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

82 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🐚 Miguishell

42 Project C License Build Status

A fully functional shell implementation in C, created as part of the 42 curriculum. This project demonstrates advanced C programming concepts including process management, signal handling, and lexical analysis using finite state automata.

🌟 Features

Core Functionality

  • Interactive Shell: Full command-line interface with custom prompt
  • Command Execution: Execute external programs and built-in commands
  • Pipe System: Support for multiple pipes (cmd1 | cmd2 | cmd3)
  • Redirections: Input/output redirection with >, >>, <
  • Heredoc: Here document support with <<
  • Environment Variables: Full environment variable management

Built-in Commands

  • echo - Print arguments with -n flag support
  • cd - Change directory with proper error handling
  • pwd - Print working directory
  • env - Display environment variables
  • export - Set environment variables
  • unset - Remove environment variables
  • exit - Exit shell with optional exit code

Advanced Features

  • Signal Handling: Proper Ctrl+C and Ctrl+D behavior
  • Variable Expansion: $VAR and $? expansion
  • Quote Handling: Single and double quote processing
  • Command History: Full readline integration
  • Error Handling: Comprehensive error messages with colors
  • Lexical Analysis: Finite state automata for parsing

πŸ—οΈ Architecture

minishell/
β”œβ”€β”€ includes/          # Header files
β”‚   β”œβ”€β”€ minishell.h    # Main header
β”‚   β”œβ”€β”€ structs.h      # Data structures
β”‚   └── executer.h     # Execution functions
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ builtins/      # Built-in commands
β”‚   β”œβ”€β”€ executer/      # Command execution
β”‚   β”œβ”€β”€ expander/      # Variable expansion
β”‚   └── utils/         # Utility functions
β”œβ”€β”€ parser/            # Lexical analysis
β”œβ”€β”€ reparser/          # Token processing
└── libft/             # Custom C library

πŸš€ Installation & Usage

Prerequisites

  • GCC compiler
  • Make
  • readline library (sudo apt-get install libreadline-dev on Ubuntu)

Compilation

git clone https://github.com/migclay12/minishell.git
cd minishell
make

Running

./minishell

πŸ“– Usage Examples

Basic Commands

$ echo "Hello World"
Hello World

$ pwd
/home/user/minishell

$ ls -la
total 48
drwxr-xr-x  8 user user 4096 May 16 19:05 .
drwxr-xr-x  3 user user 4096 May 16 18:45 ..
...

Pipes and Redirections

$ cat file.txt | grep "pattern" | wc -l
5

$ echo "Hello" > output.txt
$ cat output.txt
Hello

$ wc -l < input.txt
10

$ cat << EOF
> This is a heredoc
> It can span multiple lines
> EOF
This is a heredoc
It can span multiple lines

Environment Variables

$ export MY_VAR="Hello World"
$ echo $MY_VAR
Hello World

$ echo "Exit status: $?"
Exit status: 0

πŸ”§ Technical Details

Parser Architecture

The shell uses a finite state automata for lexical analysis:

  • States: Handle different parsing contexts (quotes, pipes, etc.)
  • Actions: Token generation and error handling
  • Alphabet: Character classification for state transitions

Process Management

  • Fork-exec model: Proper process creation and management
  • Signal handling: SIGINT, SIGQUIT, and SIGTERM support
  • Exit codes: Proper exit status propagation

Memory Management

  • No memory leaks: Comprehensive cleanup functions
  • Error handling: Graceful failure with proper cleanup
  • Dynamic allocation: Efficient memory usage

πŸ§ͺ Testing

The project includes comprehensive testing for:

  • Basic command execution
  • Pipe functionality
  • Redirection handling
  • Built-in commands
  • Error conditions
  • Signal handling

Running Tests

# Test basic functionality
make test

# Test specific features
./test_pipes.sh
./test_redirections.sh
./test_builtins.sh

πŸ“Š Performance

  • Startup time: < 50ms
  • Memory usage: < 2MB baseline
  • Command execution: Native performance
  • Pipe throughput: Limited only by system capabilities

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘¨β€πŸ’» Author

Miguel GonzΓ‘lez Clayton - migclay12

πŸ™ Acknowledgments

  • 42 School curriculum for the project requirements
  • The readline library for command history
  • The C community for best practices and examples

πŸ“ˆ Project Stats

GitHub stars GitHub forks GitHub issues GitHub pull requests


⭐ Star this repository if you found it helpful!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors