A custom UNIX shell implemented in both C and Rust, supporting built-in commands, external program execution, and single-pipe piping.
- Interactive REPL loop with a
>prompt - Built-in commands:
cd,ls,help,exit - External command execution via
fork/execvp(C) andstd::process::Command(Rust) - Single pipe (
|) support between two commands - Inline comment stripping — anything after
#on a line is ignored - Dynamic input buffer that grows as needed (C implementation)
.
├── C
│ ├── Makefile
│ ├── my_shell
│ └── shell.c
├── docs
│ └── README.md
└── Rust
├── Cargo.lock
├── Cargo.toml
├── src
│ └── main.rs
└── target
- C build: GCC or Clang
- Rust build: Rust toolchain (
rustc+cargo) — install via rustup
# Build the C version
make
# Or build the Rust version
cargo build --release# C version
./shell
# Rust version
./target/release/<project-name>| Command | Description |
|---|---|
cd <path> |
Change the current working directory |
ls [path] |
List directory contents (defaults to .) |
help |
Display help and list all built-in commands |
exit |
Exit the shell |
# Navigate directories
> cd /home/user/projects
# List files
> ls
> ls /etc
# Pipe output between commands
> ls | grep main
# Run any external program
> echo "Hello, World!"
> cat shell.c
# Inline comments are ignored
> echo hello # this part is ignored
hello- Uses
fork()+execvp()for process creation and execution - Manual memory management with
malloc/realloc/free - Pipe support via
pipe(),dup2(), and twofork()calls - Input buffer doubles in size when capacity is exceeded
strtok_rused for thread-safe line tokenization
- Uses
std::process::Commandfor spawning child processes - Pipe support via
Stdio::piped()and.stdout.take() - Leverages Rust's ownership model — no manual memory management needed
env::set_current_dirforcd,fs::read_dirforls- Pattern matching replaces the C-style
strcmploop for built-in dispatch
- Only a single
|pipe is supported per command (no chaining) - No support for I/O redirection (
>,<,>>) - No background process execution (
&) - No command history or tab completion