Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MiniShell++

C++ POSIX CMake Platform Status

A lightweight Unix-like shell developed in C++ using POSIX system calls. MiniShell++ demonstrates core operating system concepts including process creation, command execution, pipelines, I/O redirection, background job management, signal handling, and modular shell architecture.


πŸ“‘ Table of Contents


✨ Features

  • Built-in Commands (cd, history, exit)
  • External Command Execution
  • Single-stage Pipelines (|)
  • Input Redirection (<)
  • Output Redirection (>)
  • Append Redirection (>>)
  • Background Job Execution (&)
  • Signal Handling (SIGINT, SIGCHLD)
  • Command History
  • Filename Completion Engine (complete <prefix>)
  • Modular C++ Architecture
  • CMake Build System

πŸ› οΈ Technologies

  • C++17
  • POSIX System Calls
  • Linux / macOS
  • CMake

πŸ“ Project Structure

MiniShell++
β”‚
β”œβ”€β”€ assets/
β”‚   β”œβ”€β”€ shell-demo.png
β”‚   β”œβ”€β”€ pipeline.png
β”‚   β”œβ”€β”€ redirection.png
β”‚   β”œβ”€β”€ background-job.png
β”‚   └── history.png
β”‚
β”œβ”€β”€ include/
β”‚   β”œβ”€β”€ autocomplete.h
β”‚   β”œβ”€β”€ builtin.h
β”‚   β”œβ”€β”€ command.h
β”‚   β”œβ”€β”€ executor.h
β”‚   β”œβ”€β”€ history.h
β”‚   β”œβ”€β”€ parser.h
β”‚   β”œβ”€β”€ pipeline.h
β”‚   β”œβ”€β”€ process.h
β”‚   β”œβ”€β”€ shell.h
β”‚   └── signal_handler.h
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ autocomplete.cpp
β”‚   β”œβ”€β”€ builtin.cpp
β”‚   β”œβ”€β”€ command.cpp
β”‚   β”œβ”€β”€ executor.cpp
β”‚   β”œβ”€β”€ history.cpp
β”‚   β”œβ”€β”€ main.cpp
β”‚   β”œβ”€β”€ parser.cpp
β”‚   β”œβ”€β”€ process.cpp
β”‚   β”œβ”€β”€ shell.cpp
β”‚   └── signal_handler.cpp
β”‚
β”œβ”€β”€ tests/
β”œβ”€β”€ assets/
β”œβ”€β”€ build/
β”œβ”€β”€ CMakeLists.txt
β”œβ”€β”€ README.md
└── .gitignore

βš™οΈ POSIX System Calls Used

MiniShell++ is built using core POSIX APIs.

System Call Purpose
fork() Create child processes
execvp() Execute external commands
waitpid() Wait for child processes
pipe() Inter-process communication
dup2() Redirect standard input/output
open() Open files for redirection
close() Close file descriptors
sigaction() Install signal handlers

πŸš€ Build Instructions

Clone Repository

git clone https://github.com/Balpreet1003/MiniShell++.git

cd MiniShell++

Build

mkdir build

cd build

cmake ..

make

Run

./myshell

πŸ’» Usage

External Commands

pwd

ls -la

mkdir demo

whoami

Pipeline

echo hello | wc

ls | wc

Input / Output Redirection

echo hello > out.txt

echo world >> out.txt

cat < out.txt

Background Jobs

sleep 10 &

File Completion

complete out

πŸ“ Built-in Commands

Command Description
cd Change current directory
history Display command history
exit Exit MiniShell

πŸ“‹ Sample Session

myshell> pwd
/Users/balpreet_singh/Documents/MiniShell++

myshell> ls
build
include
src
README.md
CMakeLists.txt

myshell> echo hello > out.txt

myshell> cat out.txt
hello

myshell> echo world >> out.txt

myshell> cat out.txt
hello
world

myshell> ls | wc
       7       7      76

myshell> sleep 10 &
[12345] Running in background

myshell> history
1 pwd
2 ls
3 echo hello > out.txt
4 cat out.txt
5 sleep 10 &
6 history

myshell> exit

⚠️ Current Limitations

This project intentionally focuses on implementing the core functionality of a Unix shell.

Currently, the following features are not supported:

  • Multiple pipelines (cmd1 | cmd2 | cmd3)
  • Combined pipeline and redirection
  • Environment variable expansion ($PATH)
  • Wildcard expansion (*)
  • Quote parsing
  • Command aliases
  • Interactive Tab completion (uses complete <prefix>)

πŸš€ Future Improvements

Potential future enhancements include:

  • Multiple pipeline support
  • Environment variable expansion
  • Wildcard expansion
  • Quote parsing
  • Interactive Tab completion using termios or GNU Readline
  • Job control (jobs, fg, bg)
  • Persistent command history
  • Colored shell prompt

πŸ“Έ Screenshots

1. Shell Startup

Launch the shell and execute standard Unix commands.

./myshell

pwd

ls

whoami


2. Pipeline Execution

echo hello | wc

ls | wc


3. Input / Output Redirection

echo hello > out.txt

echo world >> out.txt

cat out.txt

cat < out.txt


4. Background Job Execution

sleep 10 &

pwd

history


5. Command History

history


🎯 Learning Outcomes

Through this project, I gained practical experience with:

  • Unix Shell Design
  • Operating System Fundamentals
  • POSIX System Calls
  • Process Management
  • Inter-Process Communication
  • File Descriptor Manipulation
  • Signal Handling
  • Modular C++ Software Design
  • CMake Build System

πŸ‘¨β€πŸ’» Author

Balpreet Singh Gill


πŸ“„ License

This project is developed for educational and learning purposes.

About

A Unix-like shell built in C++ using POSIX system calls, featuring pipelines, I/O redirection, background jobs, signal handling, and command history.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages