Skip to content

Sidd-77/cpp-sh

Repository files navigation

Shell in C++

Overview

This is a simple shell written in C++ from scratch. It supports various shell-like features including command execution, piping, background processes, and I/O redirection.

image (1)

Features

  • Execute Commands: Run standard system commands.
  • Change Directory (cd): Navigate between directories.
  • Help Command (help): Display available commands.
  • Background Execution (&): Run processes in the background.
  • Check Background Processes (checkbg): View running background jobs.
  • Piping (|): Connect commands using pipes.
  • I/O Redirection (> and >>): Redirect command output to files.

Installation & Compilation

Prerequisites

  • C++ Compiler (G++ recommended)
  • Make (for compilation automation)

Build Instructions

To compile the shell, use the provided Makefile:

make

This generates the executable shell.

Running the Shell

After compilation, run the shell with:

./shell

Cleaning Up

To remove compiled files, run:

make clean

Usage

Running Commands

You can run any system command just like in a normal shell:

ls
pwd
echo "Hello, World!"

Changing Directories

cd <directory>

Example:

cd /home/user

Background Execution

Run a command in the background by appending &:

top &

Use checkbg to view background processes:

checkbg

Piping Commands

Use | to pass the output of one command as input to another:

ls | grep .cpp

I/O Redirection

  • Overwrite file output:
    echo "Hello" > file.txt
  • Append to a file:
    echo "Hello Again" >> file.txt

Display Help

Run:

help

About

Shell written in C++ from scratch

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published