A custom Unix-like shell implementation written in Rust. This project provides a basic command-line interface with a REPL (Read-Eval-Print Loop) and built-in implementations of common shell utilities.
- REPL Interface: Interactive command prompt (
$or>for multi-line). - Command Parsing:
- Handles single (
') and double (") quotes. - Supports escape characters (
\). - Handles multi-line input for unclosed quotes or escapes.
- Handles single (
- Built-in Commands:
cd: Change the current working directory.pwd: Print the current working directory.echo: Display a line of text (supports escape sequences like\n,\t, etc.).exit: Terminate the shell session.
The shell includes custom implementations of standard Unix utilities found in src/commands/:
ls: List directory contents.- Supports
-a(show hidden files). - Supports
-l(long listing format with permissions, owner, group, size, modification time). - Supports
-F(classify output with trailing characters like/,@,*). - Handles file permissions and coloring/formatting similar to standard
ls.
- Supports
cat: Concatenate and display file contents.cp: Copy files and directories.mv: Move or rename files and directories.rm: Remove files or directories (supports-rfor recursive deletion).mkdir: Create new directories.
.
├── Cargo.toml # Project configuration and dependencies
├── src/
│ ├── main.rs # Entry point
│ ├── shell.rs # Main REPL loop and input handling
│ ├── parser.rs # Command string parsing logic
│ └── commands/ # Implementation of shell commands
│ ├── cat.rs
│ ├── cd.rs
│ ├── cp.rs
│ ├── echo.rs
│ ├── ls.rs
│ ├── mkdir.rs
│ ├── mod.rs # Command dispatcher
│ ├── mv.rs
│ ├── pwd.rs
│ └── rm.rs
- chrono: Used for formatting time stamps in
ls. - libc: Used for accessing low-level file permissions and system calls.
- users: Used for resolving user and group IDs to names in
ls.
- Rust and Cargo (latest stable version recommended).
-
Clone the repository (if applicable) or navigate to the project directory.
-
Build the project:
cargo build --release
-
Run the shell:
cargo run
Once inside the shell, you can execute commands as you would in a standard Unix shell:
$ ls -la
$ mkdir new_folder
$ cd new_folder
$ echo "Hello, World!" > file.txt
$ cat file.txt
$ cd ..
$ rm -r new_folder
$ exit