This project has been created as part of the 42 curriculum by surayama, kjikuhar.
Minishell is a simplified shell implementation written in C, inspired by bash. The goal of this project is to understand how a real shell works by building one from scratch: parsing user input, managing environment variables, handling redirections and pipes, and executing commands.
Key features include:
- Interactive prompt with command history (GNU readline)
- Tokenization and parsing of shell commands into an AST (Abstract Syntax Tree)
- Pipes (
|) and redirections (<,>,>>,<<) - Environment variable expansion (
$VAR,$?) - Quote handling (single and double quotes)
- Here-documents (
<<) - Built-in commands:
echo,cd,pwd,export,unset,env,exit - Signal handling (
Ctrl+C,Ctrl+D,Ctrl+\)
- GCC, Make, GNU readline library
# Build the project
make
# Run the shell
./minishell| Command | Description |
|---|---|
make |
Build the project |
make re |
Clean rebuild |
make clean |
Remove object files |
make fclean |
Remove object files and binary |
$ ./minishell
minishell$ echo hello world
hello world
minishell$ ls -la | grep Makefile
-rw-r--r-- 1 user staff 2048 Apr 10 12:00 Makefile
minishell$ export FOO=bar
minishell$ echo $FOO
bar
minishell$ cat << EOF
> hello
> world
> EOF
hello
world
minishell$ exit
The shell follows an interpreter pipeline:
Input -> tokenize() -> heredoc() -> parse() -> AST -> expand() -> execute
- Tokenizer -- State-machine-based lexer that splits input into tokens at operator, space, and quote boundaries.
- Heredoc -- Processes here-document redirections before parsing.
- Parser -- Recursive descent parser that produces a binary AST with
PIPE,AND,OR,SUBSHELL(internal) andCMD(leaf) nodes. - Expand & Execute -- Walks the AST and, for each command, applies expansion (tilde,
$?, parameter, wildcard, quote removal) then executes viafork/execve.
- The Open Group Base Specifications -- Shell Command Language
- Bash Reference Manual
- Writing Your Own Shell (42 tutorial)
- GNU Readline Library Documentation
AI (Claude Code by Anthropic) was used as a development assistant for the following tasks:
- Code review and debugging assistance
- Generating boilerplate code and Makefile configurations