Skip to content

Islam-Imad/GazaShell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GazaShell

GazaShell is a custom shell implementation written in C and C++. It provides a command-line interface for executing commands with support for input/output redirection, pipelines, and conditional execution.

Features

  • Command Processing: Tokenizes and parses user input into executable commands
  • Pipelines: Connect multiple commands with pipes (|)
  • Conditional Execution: Support for && and || operators
  • Sequential Execution: Execute commands in sequence with ;
  • Parallel Commands: Run commands in Parallel using &
  • I/O Redirection: Handle input (<), output (>), and error (2>) redirection
  • Built-in Commands: Includes essential commands like cd, pwd, path, and exit

Example Commands

Example Usage

Project Structure

.
├── src/
│   ├── builtin.c        # Built-in command implementations
│   ├── command.c        # Command execution logic
│   ├── conditional_cmd.c # Conditional command handling
│   ├── list.c           # List data structure implementation
│   ├── parser.c         # Command parsing module
│   ├── path.c           # Path management
│   ├── pipe.c           # Pipeline implementation
│   ├── scanner.c        # Input tokenization
│   ├── include/         # Header files
│       ├── builtin.h
│       ├── command.h
│       ├── conditional_cmd.h
│       ├── list.h
│       ├── parser.h
│       ├── path.h
│       ├── pipe.h
│       ├── scanner.h
├── v0/
│   ├── GazaShell.cpp    # Initial implementation
├── main.c               # Main entry point
├── README.md

Architecture

Scanner

Tokenizes user input by breaking it down into individual tokens using delimiters like spaces and tabs.

Parser

Processes tokens into structured commands, handling operators for redirection, pipelines, and conditional execution.

Execution Engine

Manages command execution through system calls, implements I/O redirection, and handles exit statuses.

Built-in Commands

Native shell functions that don't spawn new processes, including:

  • cd: Change directory
  • pwd: Print working directory
  • path: Manage command search paths
  • exit: Terminate the shell

Building and Running

  1. Build the project:

    mkdir build
    cd build
    cmake ..
    make
  2. Run GazaShell:

    ./wish

Usage Examples

Basic Commands

wish> ls -l
wish> pwd

Pipelines

wish> ls -l | grep ".c" | wc -l

I/O Redirection

wish> ls > files.txt
wish> cat < input.txt
wish> find / -name "*.c" 2> errors.log

Conditional Execution

wish> mkdir test && cd test || echo "Failed to create directory"

Parallel Commands

wish> echo a & echo b & echo c & echo d

Sequential Execution

wish> echo "First command"; echo "Second command"

Built-in Commands

wish> cd /path/to/directory
wish> pwd
wish> exit

Path Management

wish> path /bin /usr/bin /usr/local/bin

Contributing

Contributions are welcome! Feel free to submit issues or pull requests for bug fixes, enhancements, or new features.

About

simple implementation for Unix shell in C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published