A small Unix shell in C focused on parsing, builtins, pipes, redirections and signal handling.
parsing, execve, pipes, redirections, heredoc, builtins, environment, signals
Minishell is a project developed as part of the 42 curriculum.
This repository implements an interactive shell loop based on readline, a parsing layer that builds command and redirection structures, and an execution layer that dispatches builtins, external commands, pipes and redirections.
This project focuses on:
- interactive command reading and shell loop management
- quote-aware parsing and token organization
- process creation with
fork,execveandwait - file descriptor management for pipes, redirections and heredocs
- ✅ Interactive prompt with
readlinehistory support - ✅ Builtins:
echo,cd,pwd,export,unset,env,exit - ✅ Pipe execution for chained commands
- ✅ Redirections:
<,>,>>and<< - ✅ Signal handling for interactive mode and heredoc interruption
⚠️ Current parser design only exposes command, pipe and redirection tokens, so control operators such as&&,||or subshells are not implemented in this repository
This project covers the following concepts:
- linked-list based token and redirection structures
- quote-aware string parsing
- environment duplication and mutation
- process lifecycle management
- file descriptor duplication with
dupanddup2 - manual memory management and cleanup paths
Clone the repository and compile the project:
git clone git@github.com:Middle-555/minishell.git
cd minishell
makeAvailable Makefile rules:
make
make clean
make fclean
make reAdditional notes:
- The repository also provides a
make rapidetarget for a quieter build. - The build links against
readlinewith-lreadline.
Run the program with:
./minishell./minishell
echo "hello from minishell"
ls -l | grep minishell > out.txt
cat << EOF
heredoc line
EOFUsage notes:
mainexpects no extra CLI arguments and exits immediately ifargc != 1.Ctrl-Dexits the shell and printsexit.- Once the prompt is open, commands are entered interactively inside
minishell.
.
├── Makefile
├── include/
│ ├── minishell.h
│ └── utils/
│ ├── ft_printf/
│ ├── gnl/
│ └── libft/
├── srcs/
│ ├── builtin/
│ ├── envp/
│ ├── exec/
│ ├── parsing/
│ └── main.c
├── LICENSE
├── template.md
└── README.md
include/: main project headers and shared declarationssrcs/: application source files grouped by responsibilitysrcs/builtin/: builtin command implementations and builtin dispatchingsrcs/parsing/: tokenization, quote handling, expansion logic and redirection parsingsrcs/exec/: command execution, pipes, redirections, heredocs and signal flowinclude/utils/: local utility libraries (libft,ft_printf,get_next_line)
This repository is clearly organized around the 42 Minishell project scope:
- written in C
- centered on an interactive shell executable named
minishell - structured around parsing, execution, environment handling and builtins
- relies on manual memory management
- uses GNU Readline for the prompt layer
Testing in this repository is mainly manual:
- interactive command execution checks
- builtin behavior checks
- pipeline and redirection scenarios
- heredoc and signal interruption scenarios
- environment mutation and exit status checks
./minishell
echo "test" | cat
cat << EOF
hello
EOFvalgrind --leak-check=full --track-fds=yes ./minishellThis kind of project helps improve in the following areas:
- separating parsing concerns from execution concerns
- reasoning about processes and file descriptors
- handling shell edge cases around quotes, pipes and redirections
- cleaning dynamic allocations reliably in error and exit paths
Although the project already covers the core minishell mechanics, several improvements are possible:
- replace Linux-specific headers with a more portable alternative
- add an automated regression test suite
- extend the parser to support more shell grammar features
- align edge-case behavior even more closely with Bash semantics
This project is distributed under the MIT license. See LICENSE.