Skip to content

A custom command-line shell written in pure C. 2600+ lines featuring pipelines, I/O redirection, aliases, history, and 30+ built-in commands.

License

Notifications You must be signed in to change notification settings

shiva-kar/CShell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CShell - Custom Command Line Shell 🐚

A fully-featured command-line shell written in pure C with no external dependencies. Implements core Unix shell features on Windows.

Language Platform License Lines

✨ Features

Core Shell Features

  • Command Execution - Run any Windows executable or batch file
  • Pipeline Support - Chain commands with | (e.g., ls | grep txt)
  • I/O Redirection - Input <, output >, append >>
  • Background Jobs - Run commands in background with &

Built-in Commands (30+)

Category Commands
Navigation cd, pwd, ls (with -a, -l flags)
File Ops cat, touch, mkdir, rmdir, rm, cp, mv
Shell echo, alias, unalias, history, export, env
System whoami, hostname, date, time, which, clear
Control exit, help, version

Advanced Features

  • Command History - Persistent history saved to ~/.cshell_history
  • Aliases - Create shortcuts (e.g., alias ll="ls -l")
  • Variable Expansion - $VAR, ${VAR}, $? (exit code), $$ (PID)
  • Home Directory - ~ expands to user profile
  • Color Output - Syntax highlighting for prompts, errors, and ls

📦 Project Structure

CShell/
├── include/
│   └── shell.h          # Core header with all definitions
├── src/
│   ├── main.c           # Entry point
│   ├── shell.c          # Shell initialization and main loop
│   ├── parser.c         # Command parsing and tokenization
│   ├── builtins.c       # Built-in command implementations
│   ├── executor.c       # External command and pipeline execution
│   ├── history.c        # Command history management
│   ├── utils.c          # Utility functions (colors, prompts, etc.)
│   ├── alias.c          # Alias management
│   └── env.c            # Environment variable handling
├── CMakeLists.txt       # Build configuration
├── LICENSE              # MIT License
└── README.md

🚀 Building

Prerequisites

  • GCC (MinGW-w64 on Windows) or MSVC
  • CMake 3.11+

Build Commands

# Create build directory
mkdir build && cd build

# Configure
cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release ..

# Build
cmake --build .

# Run
./cshell

Quick Build (MinGW)

gcc -std=c11 -O2 -Wall -Iinclude src/*.c -o cshell.exe

🎮 Usage

Interactive Mode

./cshell

Script Mode

./cshell script.sh

Example Session

╔═══════════════════════════════════════════════════════╗
║   CShell - Custom Command Line Shell                  ║
║   Version 1.0.0                                       ║
║   Type 'help' for available commands                  ║
╚═══════════════════════════════════════════════════════╝

user@DESKTOP:~/projects $ ls -l
drwxr-xr-x       <DIR>  2026-01-13 03:30  CShell/
-rw-r--r--      1.2K  2026-01-13 03:25  README.md

user@DESKTOP:~/projects $ cd CShell

user@DESKTOP:~/projects/CShell $ cat README.md | head

user@DESKTOP:~/projects/CShell $ alias ll="ls -l"

user@DESKTOP:~/projects/CShell $ ll > files.txt

user@DESKTOP:~/projects/CShell $ history 5
     1  12:30  ls -l
     2  12:30  cd CShell
     3  12:31  cat README.md | head
     4  12:31  alias ll="ls -l"
     5  12:31  ll > files.txt

user@DESKTOP:~/projects/CShell $ exit

💡 Technical Highlights

What This Project Demonstrates

  1. Systems Programming

    • Process creation with CreateProcess() Windows API
    • Handle inheritance for I/O redirection
    • Signal handling and process management
  2. Data Structures

    • Doubly linked list for command history
    • Dynamic arrays for tokenization
    • Hash-like structures for aliases and environment
  3. Parsing & Compilation Concepts

    • Lexical analysis (tokenization)
    • Syntax parsing (command structure)
    • Variable expansion and substitution
  4. Memory Management

    • Manual allocation/deallocation
    • No memory leaks (Valgrind clean equivalent)
    • Proper cleanup on exit
  5. Software Architecture

    • Modular design (separate concerns)
    • Clean API between components
    • Extensible command system

🔮 Future Enhancements

  • Tab completion
  • Command line editing (arrow keys)
  • Job control (fg, bg, jobs)
  • Scripting (if/else, loops, functions)
  • Glob patterns (*.txt, file?)
  • Configuration file (.cshellrc)

📄 License

MIT License - See LICENSE


Author: Shiva Kar
Built with: Pure C (C11) - No external dependencies
Lines of Code: 2000+

A real systems programming project demonstrating low-level C skills.

About

A custom command-line shell written in pure C. 2600+ lines featuring pipelines, I/O redirection, aliases, history, and 30+ built-in commands.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published