A simple shell implementation inspired by bash, developed as part of the 42 School curriculum.
Minishell is a simplified shell that implements basic functionality similar to bash. This project challenges students to understand how shells work, process management, and file descriptors while building a functional command-line interpreter.
- Display a prompt while waiting for a new command
- Working history management
- Search and execute commands based on PATH variable or using relative/absolute path
- Handle quotes (
'
and"
) and special characters - Implement redirections (
<
,>
,<<
,>>
) - Implement pipes (
|
) - Handle environment variables (
$
followed by characters) - Handle
$?
which expands to the exit status - Handle signals (
ctrl-C
,ctrl-D
,ctrl-\
)
echo
with option-n
cd
with relative or absolute pathpwd
without any optionsexport
without any optionsunset
without any optionsenv
without any optionsexit
without any options
# Clone the repository
git clone https://github.com/NzolaKiampava/minishell.git
# Navigate to the project directory
cd minishell
# Compile the project
make
# Run minishell
./minishell
# Basic command execution
$> ls -la
# Using pipes
$> ls | grep filename
# Input/Output redirections
$> echo "hello" > output.txt
$> cat < input.txt
# Environment variables
$> echo $PATH
# Built-in commands
$> cd ..
$> pwd
$> echo "Hello World"
minishell/
├── Makefile
├── includes/
│ └── minishell.h
├── libft/
│ ├── Makefile
│ └── [libft source files]
├── src/
│ ├── main.c
│ ├── builtins/
│ │ ├── cd.c
│ │ ├── echo.c
│ │ ├── env.c
│ │ ├── exit.c
│ │ ├── export.c
│ │ ├── pwd.c
│ │ └── unset.c
│ ├── executor/
│ │ ├── executor.c
│ │ ├── pipe_handler.c
│ │ └── redirections.c
│ ├── parser/
│ │ ├── parser.c
│ │ ├── tokenizer.c
│ │ └── expander.c
│ ├── signals/
│ │ └── signals.c
│ └── utils/
│ ├── environment.c
│ └── error_handler.c
-
Builtins (
src/builtins/
)- Implementation of all required shell built-in commands
- Each command in a separate file for better organization
-
Executor (
src/executor/
)executor.c
: Main command execution logicpipe_handler.c
: Handles pipe operations between commandsredirections.c
: Manages input/output redirections
-
Parser (
src/parser/
)parser.c
: Command line parsing and structure creationtokenizer.c
: Splits input into tokensexpander.c
: Handles environment variable expansion
-
Signals (
src/signals/
)signals.c
: Handles all signal-related functionality
-
Utils (
src/utils/
)environment.c
: Environment variable managementerror_handler.c
: Error handling and messaging
The shell has been tested with:
- Basic command execution
- Complex pipe sequences
- Various types of redirections
- Edge cases with quotes and special characters
- Memory leak checks using Valgrind
- Error handling scenarios
- Does not handle advanced features like wildcards (
*
) - No command history file persistence between sessions
- Limited signal handling compared to bash
This project is licensed under the MIT License - see the LICENSE file for details.
- 42 School for the challenging project
- Fellow 42 students for testing and feedback
- The open-source community for valuable resources