Skip to content

A Unix-like shell implemented in C, created as a mini project for Operating Systems and Networks course.

License

Notifications You must be signed in to change notification settings

Shreyas-Agarwal27/C-Shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C-Shell

A custom shell implementation in C that supports command execution, job control, piping, and persistent command history. It features a custom parser and state management system for interactive terminal use.

Features

  • Directory Navigation (hop): Replacement for cd. Supports absolute/relative paths, ~, ., .., and - (previous directory). Multiple arguments are processed sequentially.
  • Directory Listing (reveal): Replacement for ls. Supports -l (long format) and -a (show hidden files).
  • Persistent History (log): Latest 15 commands are stored in logs.txt. View, purge, or re-execute commands by index. Commands starting with log are not logged to prevent recursion.
  • Job Control:
    • Background Execution: Use & to run commands in the background.
    • activities: Lists running/stopped background jobs.
    • fg / bg: Bring jobs to foreground or resume in background.
    • ping: Send signals to processes by PID. Signal number is mapped as signal_num % 32.
  • System Interactions:
    • Piping (|): Chain commands, passing output as input.
    • I/O Redirection: Supports <, >, and >>.
    • Signal Handling: Handles Ctrl+C (SIGINT) to terminate foreground processes and Ctrl+D (EOF) to exit.

Compilation & Usage

make            # Compile the shell
./shell.out     # Run the shell
make run        # Compile and run
make clean      # Remove build artifacts

Assumptions

  • Command Names: Uses hop, reveal, log, and activities instead of cd, ls, history, and jobs.
  • Signal Mapping: ping applies modulo 32 to signal numbers.
  • Job Limit: Maximum 100 background jobs.
  • Termination Notifications: Background job completion is reported at the next prompt, not immediately.
  • Job Selection Logic: When fg or bg is run without a job ID, the shell selects the oldest active job available.
  • Parsing Redirection Symbols: Redirection operators (<, >, >>) must be preceded by a space; otherwise, the syntax is considered invalid.
  • Multiple Output Redirections: When multiple output redirections are present (e.g., command > file1 > file2), only the last one takes effect; all previous output redirections are ignored.
  • Sequential hop: If multiple arguments are provided to hop command, it sequentially processes them and stops once at the end or it encounters any invalid directory name.

Project Structure

Makefile
LICENSE
README.md
include/
        *.h        # Header files for modules
src/
        *.c        # Source files for modules

Modules

  • hop: Directory navigation
  • reveal: Directory listing
  • log: Command history
  • activities: Job management
  • ping: Signal sending
  • prompt, command, parser, shell_state, signal_handle: Core shell logic

Notes

  • Designed for educational purposes and experimentation.
  • Not POSIX-compliant; intended as a learning project.

About

A Unix-like shell implemented in C, created as a mini project for Operating Systems and Networks course.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published