Skip to content

anuow/Shell-Rust-Project

Repository files navigation

Rust Shell

A fully functional Unix-like shell written from scratch in Rust.
Built as part of my journey to learn Rust systems programming and understand how shells work internally — from parsing commands to handling pipelines and redirections.


Features

  • Interactive prompt ($ ) with input history
  • Built-in commands:
    • cd — change directory
    • pwd — print current directory
    • echo — print text
    • exit [code] — exit the shell
    • type — identify if a command is a builtin or external
    • history — view, read, write, or append command history
  • Pipelines:
    Supports multi-stage command chaining like
    cat file.txt | head -n 5 | wc -l

I made this project to learn Rust Rebuilding something as fundamental as a shell from the ground up helped me understand both Rust’s safety guarantees and how real shells like bash/zsh work internally.

Redirection

Output/input redirection with:

echo hello > file.txt
echo again >> file.txt
cat file.txt 2> errors.log
  • Command autocompletion for builtins and executables in $PATH
  • Persistent history through the HISTFILE environment variable
  • Error handling for invalid commands, missing files, and pipes

How It Works

  • Parsing: Tokenizes user input, handling quotes, pipes, and redirects.
  • Execution: Forks processes for external commands, connects pipes using libc and nix.
  • Builtins: Runs in-process without forking.
  • History: Managed in-memory with optional persistent storage via HISTFILE.

Build & Run

Prerequisites

Rust

Clone and build

git clone https://github.com/<your-username>/Shell-Rust-Project.git
cd rust-shell
cargo build --release

Run

./target/release/Shell-Rust-Project

Run with history file

HISTFILE=~/.my_shell_history ./target/release/Shell-Rust-Project

Tech & Concepts Used

  • Rust standard library (std::process, std::fs, std::io)
  • UNIX syscalls (fork, exec, pipe, dup2) via nix
  • Rustyline for interactive input and autocompletion
  • Manual command parsing, quoting, and redirection logic

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published