Skip to content

albadra2/custom-c-shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Custom C Shell

Overview

This project implements a simple Unix-style shell in the C programming language, called customshell.

The project is delivered in 3 stages (Stage 1, Stage 2, Stage 3) with incremental functionality.


Features

Stage 1

  • Internal Commands
    • cd – change current directory (or display if no argument). Updates $PWD.
    • clr – clear the terminal screen.
    • dir – list directory contents (like ls -al).
    • environ – display all environment variables.
    • echo – print arguments (collapsing multiple spaces/tabs).
    • help – display user manual with more filter.
    • pause – pause execution until Enter is pressed.
    • quit – exit the shell.
  • Batch Mode
    • If invoked as ./customshell batchfile, commands are read and executed from the file.
  • Shell Environment
    • Sets environment variable shell=/path/to/customshell.

Stage 2

  • External Commands
    • Launch programs using fork + exec, with parent=/path/to/customshell added to environment.
  • I/O Redirection
    • Input < inputfile
    • Output overwrite > outputfile
    • Output append >> outputfile
    • Works for both internal (dir, environ, echo, help) and external commands.
  • Background Execution
    • Commands ending with & run in the background while shell prompt remains available.

Stage 3

  • Demonstration Video
    • 5-minute video showing:
      • Operation of internal commands.
      • Running external commands in background (e.g. ./sleepy 5 &).
      • Demonstration of I/O redirection.
      • Code walkthrough (focus on external commands, fork/exec, redirection with freopen / dup).

Project Structure

  • makefile – builds the customshell binary.
  • customshell.c – main shell implementation.
  • utility.c – supporting functions.
  • customshell.h – header definitions.
  • Stage1/, Stage2/, Stage3/ – submission directories for each project stage.

Building

Compile the shell using the provided makefile:

make

This generates the executable:

./customshell

Usage

Interactive Mode Run the shell directly:

./customshell

Prompt will show the current working directory.

Batch Mode

Provide a batch file:

./customshell batchfile

Executes all commands in the file sequentially.

Example Commands

cd /home/user
dir
echo Hello World
environ
pause
quit

I/O Redirection Examples

dir > out.txt
echo Hello >> log.txt
./myprogram < input.txt > output.txt

Background Execution

./sleepy 5 &
dir

User Manual (Beginner - Friendly)

  • cd [dir] – change directory, or show current if none given.
  • clr – clear screen.
  • dir [dir] – list contents of a directory.
  • environ – show all environment variables.
  • echo [text] – print text.
  • help – open manual.
  • pause – wait until Enter is pressed.
  • quit – exit the shell.
  • [program] [args] – run external program.
  • [command] < infile > outfile – redirect input/output.
  • [command] & – run process in background.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors