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:~$ _- Execution of external commands using
fork,execvp, andwaitpid. - 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,Tabcompletion,history,!n)
The shell follows a modular design:
Tokenizer → Parser → AST → Executor
- Converts raw input into tokens (commands, operators, redirections, parentheses).
-
Builds an AST respecting operator precedence:
;→ lowest
&&and||
|
command/subshell → highest -
- Command
- Pipeline
- Logical
- Sequence
- Subshell
-
- Recursively evaluates AST nodes using post-order traversal
- Forks processes where required
- Preserves shell state for built-ins
# Ubuntu / Debian
sudo apt install build-essential
mkdir build
cd build
cmake ..
make
./mnsh or gnome-terminal -- ./mnsh (for new tab in terminal)Distributed under the MIT License. See LICENSE for details.