Skip to content

Latest commit

 

History

History
185 lines (131 loc) · 5.96 KB

File metadata and controls

185 lines (131 loc) · 5.96 KB

Here’s your revised README with the improvements added for clarity, structure, and a touch of personality — great for showcasing your work to employers or online:


progress-banner

🐚 Build Your Own Shell in Java

This is a custom implementation of a POSIX-compliant shell written in Java. It interprets shell commands, runs external programs, and supports built-in commands like cd, pwd, echo, and more. The shell also supports command parsing, I/O redirection, and autocompletion.

This project is part of the "Build Your Own Shell" Challenge by Codecrafters. It helped me understand how real-world shells like Bash or Zsh work under the hood while sharpening my Java skills.


📑 Table of Contents


📌 What This Project Does

This Java shell:

  • Accepts user input to execute shell commands.
  • Implements built-in commands like cd, pwd, echo, exit, and type.
  • Supports running external programs by resolving system PATH.
  • Handles input/output/error redirection (e.g., >, >>, 2>).
  • Offers command autocompletion using the Tab key.

⚙️ How to Set Up and Run

Prerequisites

  • Java 23
  • Maven
  • Linux-based system (for POSIX support)

Installation

# Clone the repo
git clone https://github.com/Md-Talim/codecrafters-shell-java.git
cd codecrafters-shell-java

# Build the project
mvn clean package

# Run the shell
./your_program.sh

Usage

  • You'll see a prompt like $
  • Enter commands like pwd, echo Hello, ls, or cd ..
  • Press Ctrl + D to exit

✨ Key Features

  • Built-in Commands:
    • cd, pwd, echo, exit, type
  • External Commands:
    • Uses ProcessBuilder to run commands found in the system PATH
  • Redirection:
    • >, >>, and 2> supported
  • Autocompletion:
    • Pressing Tab suggests available commands and executables
  • Terminal Control:
    • Uses raw input mode for better interactivity

🔍 How It Works Internally

Component Responsibility
Parser.java Breaks input into tokens, handles redirection
Shell.java Main shell logic, orchestrates commands
CommandRegistry Registers and manages built-in commands
ExternalCommand.java Executes non-built-in programs via ProcessBuilder
Redirection.java Handles output and error redirection
AutoCompleter.java Suggests commands during typing
Termios.java Enables raw terminal mode via JNA

🧰 Technologies Used

  • Java 23
  • Maven
  • JNA (Java Native Access)
  • POSIX standards for terminal and process behavior

📁 Folder and File Structure

src/
  main/
    java/
      Main.java                # Entry point
      shell/
        Shell.java             # Core shell loop
        command/               # Built-in commands
        environment/           # Env vars and state
        io/                    # I/O + redirection
        parser/                # Input parsing
        process/               # Process execution
        terminal/              # Raw mode handling
        autocomplete/          # Tab suggestions

💡 Challenges & Lessons Learned

Challenges

  • 🧩 Command Parsing: Handling quotes, escapes, and operators
  • 🔁 Redirection: Syncing output streams to files accurately
  • Autocompletion: Real-time feedback and correct suggestions
  • 🧠 Terminal Control: Raw mode and disabling echo with JNA

Lessons Learned

  • Internal working of Unix-like shells
  • Parsing and interpreting command-line input
  • Running processes and managing I/O in Java
  • Working with native system APIs using JNA
  • Structured thinking and debugging complex workflows

🛠️ Why I Built This Project

  • To understand how Bash/Zsh-like shells work under the hood
  • To practice writing clean, modular, and testable Java code
  • To solve a real-world systems-level problem from scratch
  • To push my boundaries with parsing, process control, and terminal I/O

This project helped me grow as a backend/systems engineer and is one of my favorite learning experiences.


🖼️ Demo

Optional: Add a GIF or screenshot of the shell running in a terminal.

Demo Screenshot


👨‍💻 About Me

I'm a Computer Science student who loves building things from scratch to deeply understand how they work. I'm currently exploring backend systems, shell design, operating systems, and compilers.


Let me know if you want a shorter version for LinkedIn or a portfolio site too!