Skip to content

chiranjivikeshav/MiniShell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Language Standard Status License Platform


A minimal, POSIX-compliant Unix-style shell for Linux distributions.


Table of Contents


Overview

MiniShell is a lightweight Linux shell written in C++ from the ground up. Command parsing, process forking, pipe chaining, I/O redirection, and signal handling — all in a clean, readable codebase..

mnsh:~$ echo "Hello, Shell!" | tr '[:lower:]' '[:upper:]'
"HELLO, SHELL!"
mnsh:~$ _

Features

  • Execution of external commands using fork, execvp, and waitpid.
  • Abstract Syntax Tree (AST) – based parsing for complex command structures.
  • Logical operators:
    • && (AND)
    • || (OR)
  • Sequence - ;
  • Pipelines using - |
  • Input/output/error redirections:
    • <, >, >>, 2>
  • Subshell support using parentheses ( ... ) with correct scope isolation.
  • Built-in commands like cd, exit, etc.
  • Accurate exit-status propagation enabling correct short-circuit logic.
  • Parent/child process separation for built-ins and subshells.
  • Signal handling: Supports Ctrl+C interruption for foreground commands and subshell execution, with signal isolation between parent shell and child processes.
  • Line editing & history (↑↓ navigate, ←→ cursor, Ctrl+A/E, Tab completion, history, !n)

Architecture

The shell follows a modular design:

Tokenizer → Parser → AST → Executor

  • Tokenizer

    Converts raw input into tokens (commands, operators, redirections, parentheses).
  • Parser

    Builds an AST respecting operator precedence:

    ; → lowest
    && and ||
    |
    command/subshell → highest

  • AST Nodes

    • Command
    • Pipeline
    • Logical
    • Sequence
    • Subshell
  • Executor

    • Recursively evaluates AST nodes using post-order traversal
    • Forks processes where required
    • Preserves shell state for built-ins

Build

# Ubuntu / Debian
sudo apt install build-essential
mkdir build
cd build
cmake ..
make
./mnsh  or gnome-terminal -- ./mnsh (for new tab in terminal)

License

Distributed under the MIT License. See LICENSE for details.


Author

LinkedIn GitHub Gmail Twitter Instagram