knaxuslearn · build · ship

Projects / Unix shell / Before you start

Before you start

Install Rust with rustup and check it:

cargo --version

Every listing and command in this project was run with Rust 1.97 on x86-64 Linux. The system calls we use (fork, pipe, waitpid, setpgid and friends) also exist on macOS, but we ran the guide only on Linux, so a few details of terminal behaviour may differ on your Mac. Each phase is its own Cargo project (d1, d2, and so on), so you can keep an older version next to a newer one:

cargo new d1 --name rsh

From Phase 2 on, add the libc crate, which gives Rust access to the raw system calls. Your Cargo.toml should then look like this:

[package]
name = "rsh"
version = "0.1.0"
edition = "2021"

[dependencies]
libc = "0.2"

To try the shell without typing into it, we feed it a file of commands: ./target/release/rsh < try.txt reads each line as if you had typed it, which also makes every result repeatable.