This project has been created as part of the 42 curriculum by mkugan and uwettasi.
Minishell is a Unix shell implementation written in C, built as part of the 42 curriculum. The goal is to recreate core Bash behaviour: parsing and executing commands, managing processes and file descriptors, handling signals, and implementing a set of built-in commands from scratch.
The shell features a full lexer/parser pipeline that builds an Abstract Syntax Tree (AST) from user input. Execution traverses the AST to handle simple commands, pipelines, logical operators, subshells, and I/O redirections.
Mandatory features:
- Interactive prompt with command history (readline)
- Command resolution via
PATH, relative, or absolute paths - Single (
') and double (") quote handling - I/O redirections:
<,>,>>, and heredoc<< - Pipes (
|) connecting command output to the next command's input - Environment variable expansion (
$VAR) and exit status expansion ($?) - Signal handling:
ctrl-C(new prompt),ctrl-D(exit),ctrl-\(ignored) - Built-in commands:
echo [-n],cd,pwd,export,unset,env,exit
Bonus features:
- Logical operators
&&and||with correct short-circuit evaluation - Parentheses
(...)for subshell grouping and operator precedence - Wildcard
*expansion in the current working directory
gcc(or any C99-compatible compiler)GNU readlinelibrary
On macOS (with Homebrew):
brew install readlineOn Debian/Ubuntu:
sudo apt-get install libreadline-devgit clone https://github.com/mike-k-git/42_minishell minishell
cd minishell
makeThis compiles libft first, then the shell binary minishell.
| Rule | Effect |
|---|---|
make / make all |
Build minishell |
make clean |
Remove object files |
make fclean |
Remove objects and binaries |
make re |
Full rebuild |
./minishellThe shell starts in interactive mode and displays a prompt. It behaves like a restricted Bash — use it as you would any shell.
Examples:
# Pipelines and redirections
ls -la | grep ".c" > sources.txt
# Heredoc
cat << EOF
hello world
EOF
# Logical operators and subshells
(echo "start" && make) || echo "build failed"
# Wildcard expansion
echo *.c
# Environment variables
export MY_VAR=hello
echo $MY_VAR
echo $?- Bash Reference Manual — the canonical reference for shell behaviour
- GNU Readline Library — documentation for readline, history, and terminal interaction
- The Open Group Base Specifications — Shell & Utilities — POSIX shell grammar and semantics
- The Linux Programming Interface (Kerrisk) — processes, signals, file descriptors, and pipes
- Writing Your Own Shell — various 42 community walkthroughs on AST construction and execution
AI tools were used in the following ways during this project:
- Clarifying concepts: asking about POSIX signal semantics,
waitpidflag behaviour, and edge cases in quote handling that the bash manual describes ambiguously. - Debugging assistance: describing unexpected output and asking for likely causes (e.g. pipe fd leaks in multi-stage pipelines, heredoc signal interaction).
- Code review: reviewing specific functions for memory leaks and discussing whether a given approach to glob expansion was correct.
- Documentation: drafting this README based on the project subject requirements.
All AI-generated content was reviewed, tested, and understood before being incorporated. Final decisions, implementations, and responsibility for correctness remain with the authors.