Unix Shell Implementation

Unix Shell project wordmark

Project Information

  • Category: Systems
  • Project date: Fall 2025

Project Overview

A custom Unix-like shell implemented in C++ that supports command parsing, sequential execution (;), and pipelines (|). The shell handles tokenization, process creation, cleanup of resources, and provides a foundation for adding features such as redirection or built-in commands. The project exercises core systems concepts including processes, IPC, and resource management.

Demo

Supports sequential execution with semicolons (;) and inter-process communication through pipes (|).

Graceful Error Handling

Implements graceful error handling by detecting and reporting malformed commands (e.g., missing pipe operands or multiple semicolons) without terminating the shell, allowing users to continue running valid commands.

C++ code for tokenizing shell commands

Tokenization

Converts raw user input into structured commands by splitting on delimiters (;, |, spaces) and safely allocating memory for each token. This parsing layer ensures the shell can interpret complex input like ls -l ; cat file | grep foo into discrete, executable steps.

Pipeline Execution

Implements Unix-style pipelines by creating child processes with fork(), connecting their input and output streams using pipe() and dup2(). This allows the output of one command to seamlessly become the input of the next, enabling commands like cat file | grep foo to execute as a connected process chain.

C++ code for executing shell pipelines
C++ code for cleaning up shell resources

Cleanup

Reclaims all dynamically allocated memory and clears process structures after each command cycle. This disciplined resource management prevents leaks and ensures the shell remains stable across repeated executions.