Skip to content

About

My Rust implementation of the "Build Your Own Shell" CodeCrafters Challenge

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

51 Commits

Folders and files

Repository files navigation

Build Your Own Shell - Rust

progress-banner

A POSIX-compliant shell in Rust, built for the CodeCrafters "Build Your Own Shell" challenge. Line editing and tab completion via rustyline; pipeline stages run concurrently, one thread per stage. A rewrite of my earlier C++ attempt.

What it supports

  • Builtins: echo, pwd, cd (with ~ expansion), type, history, exit
  • External commands resolved via PATH (checks the executable bit on every entry)
  • Quoting: single quotes, double quotes, and backslash escaping, following the POSIX rule that inside double quotes \ only escapes ", \, $ and `
  • Redirection: >, 1>, >>, 1>> for stdout, 2>, 2>> for stderr
  • Pipelines: cmd1 | cmd2 | cmd3, one thread per stage
  • Tab completion of builtins and all PATH executables
  • History: history [n], history -r/-w/-a <file>, loads $HISTFILE on startup and saves on exit; appends only the entries added since the last save
$ ./your_program.sh
$ echo 'hello world' | tr a-z A-Z > /tmp/out.txt
$ history 2

What I learned

  • How shell quoting works: the difference between single and double quotes, and when a backslash is special vs. literal
  • How to wire up a command's input and output to pipes, files, or the terminal
  • Running pipeline stages concurrently, so every command in a | b | c runs at the same time
  • Adding line editing and tab completion with the rustyline library

Skeleton

File Role
src/main.rs The entire shell: REPL + history (main), quoting/redirection parsing (PipelineCommand::new), pipeline setup (Pipeline::new), builtins + external spawn (PipelineCommand::run), tab completion (CommandCompleter)

About

My Rust implementation of the "Build Your Own Shell" CodeCrafters Challenge

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages