Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project has been created as part of the 42 curriculum by surayama, kjikuhar.

minishell

Description

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+\)

Instructions

Prerequisites

  • GCC, Make, GNU readline library

Build and Run

# Build the project
make

# Run the shell
./minishell

Other Make Targets

Command Description
make Build the project
make re Clean rebuild
make clean Remove object files
make fclean Remove object files and binary

Usage Examples

$ ./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

Architecture

The shell follows an interpreter pipeline:

Input -> tokenize() -> heredoc() -> parse() -> AST -> expand() -> execute
  1. Tokenizer -- State-machine-based lexer that splits input into tokens at operator, space, and quote boundaries.
  2. Heredoc -- Processes here-document redirections before parsing.
  3. Parser -- Recursive descent parser that produces a binary AST with PIPE, AND, OR, SUBSHELL (internal) and CMD (leaf) nodes.
  4. Expand & Execute -- Walks the AST and, for each command, applies expansion (tilde, $?, parameter, wildcard, quote removal) then executes via fork/execve.

Resources

Use of AI

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

About

42_Minishell用レポジトリ。

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages