Skip to content

anujsd/shell-scratch-go

Repository files navigation

progress-banner

🔧 Shell From Scratch in go

A POSIX-compliant shell implementation written in Go from scratch.

Go Version License

✨ Features

  • Command execution with argument parsing
  • Pipeline support (cmd1 | cmd2 | cmd3)
  • I/O redirection (>, >>, 2>, 2>>)
  • Built-in commands: cd, pwd, echo, exit, type, history
  • Command history with file persistence
  • Tab completion with prefix matching
  • Rich line editing (powered by readline)
  • Quote handling (single/double)
  • Home directory expansion (~)

🚀 Installation & Running

Prerequisites

# Install Go 1.24 or higher
go mod download

Quick Start

# Run the shell using the provided script
./your_program.sh

# Interactive shell will start (type 'exit' to quit)
$ echo "Hello World!"
$ ls -la
$ pwd

🛠 Technical Concepts

  • Command Processing

    • Lexical analysis and token parsing
    • Advanced quote and escape handling
    • Multi-stage pipeline execution with buffering
    • Process spawning and lifecycle management
  • Shell Features

    • File descriptor management for I/O redirection
    • History with readline integration
    • Tab completion using prefix matching
  • Go Specifics

    • Goroutines for concurrent command execution
    • Sync primitives (WaitGroup, Mutex)
    • Standard library syscall integration

Project Structure

app/
├── main.go         # Core shell implementation
├── read_env.go     # Environment and PATH handling
├── history.go      # History management
└── autocomplete.go # Completion engine

Built as part of the "Build Your Own Shell" challenge on CodeCrafters.

About

A POSIX-compliant shell implementation written in Go from scratch.

Topics

Resources

Stars

Watchers

Forks