Skip to content

Latest commit

 

History

83 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minishell

A simplified Unix shell implementation built as part of the 42 school curriculum.
Minishell supports basic shell functionalities including command execution, redirections, pipelines, environment variables, and more — all written in C, following strict 42 Norminette standards.


🛠 Key Features

📜 Commands Implemented

Category Implemented
Builtins cd, echo -n, env, export, pwd, unset, exit (with status codes)
Redirections <, >, >>, heredoc (<<) with variable expansion suppression
Pipes `
Variables $VAR, $? (exit status), SHLVL (shell level tracking)
Quotes Full handling of ' ', " ", nested quotes, and edge cases ("''", '""')
Signals Ctrl+C (SIGINT), Ctrl+\ (SIGQUIT), Ctrl+D (EOF)

📁 Project Structure

.
├── src/              # Main source code
│   ├── lexing/       # Tokenization of input
│   ├── parser/       # Building command structures
│   ├── executing/    # Command execution and pipes
│   ├── builtins/     # Built-in command functions
│   ├── functions/    # Utility functions
│   ├── cleaner/      # Setup the environment
│   ├── inc/          # Header files
│   └── signals/      # Handles signals
├── Makefile          # Build system
├── Main.c            # Entry point
└── README.md

🧠 How It Works

  1. Input: Displays a prompt and reads user input using readline (supports history navigation).
  2. Lexing: Splits input into tokens while handling:
    • Quotes ('...', "...") and escapes (\).
    • Environment variables ($VAR).
    • Metacharacters (|, >, <, etc.).
  3. Parsing:
    • Creates a token list from lexed input.
    • Merges tokens into commands by splitting on metacharacters (e.g., ls -l | grep test → 2 commands).
    • Builds an executable structure (AST) with redirections/pipes.
  4. Execution:
    • Runs builtins directly (e.g., cd, export).
    • Executes external binaries via PATH (e.g., /bin/ls).
    • Handles pipes/redirections with dup2 and fork.
  5. Cleanup: Frees memory, resets file descriptors, waits for next input.

🚫 Not Implemented

  • Logical operators (||, &&)
  • Job control (fg, bg, etc.)
  • File descriptor aggregation (2>&1, etc.)

📌 Prerequisite: install the Readline library

sudo apt update
sudo apt install libreadline-dev

📦 Compilation

make

To clean build artifacts:

make clean      # removes object files  
make fclean     # removes object files and binary  
make re         # rebuilds everything

▶️ Usage

./minishell

Once launched, you can start typing commands like:

> echo Hello World
> ls -la | grep Minishell
> export var=test
> cat << EOF
heredoc content
EOF

👨‍💻 Authors

This project was developed as part of the 42 school curriculum by:


Do not use this for cheating in the 42 program.

About

Minishell is a custom shell implementation created as part of the 42 School curriculum. It mimics a basic Unix shell, allowing users to execute commands, handle input/output redirection, support environment variables, and manage built-in commands. The project focuses on implementing fundamental shell behaviors.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages