A simple, lightweight shell implementation written in Rust.
0-shell mimics the functionality of a standard Unix shell, providing built-in implementations for common commands and handling basic shell features like command parsing and quoting.
- Interactive Shell Loop: A classic REPL (Read-Eval-Print Loop) interface.
- Command Parsing: robust parsing of input, including handling of quoted strings (single and double quotes).
- Built-in Commands: Pure Rust implementations of standard core utils:
echo: Print text to standard output.pwd: Print the current working directory.cd: Change the current directory.ls: List directory contents (supports colors and permissions if configured).mkdir: Create new directories.cat: Concatenate and display file contents.cp: Copy files and directories.mv: Move or rename files and directories.rm: Remove files and directories.clear: Clear the terminal screen.exit: Exit the shell.
Before you begin, ensure you have the Rust programming language and Cargo package manager installed on your system.
You can install Rust using rustup:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh-
Clone the repository (if you haven't already):
git clone <repository_url> cd 0-shell
-
Run the shell directly using Cargo: This will compile dependencies and start the shell in one go.
cargo run
-
Build a release binary (optional): For better performance, you can build a release version:
cargo build --release ./target/release/0-shell
Once the shell is running, you will see the prompt:
$
You can type standard commands just like in bash or zsh.
Listing files:
$ ls
Cargo.toml src targetCreating and entering a directory:
$ mkdir new_folder
$ cd new_folder
$ pwd
/path/to/0-shell/new_folderCreating a file (using echo) and reading it:
$ echo "Hello World" > hello.txt # Note: Redirection support depends on implementation details
$ cat hello.txt
Hello World(Note: If file redirection > is not fully implemented in the parser yet, echo will simply print the arguments).
Handling Consoles/Quotes: The shell supports multi-line input if a quote is left open:
$ echo "this is a
dequote> multi-line string"
this is a
multi-line stringsrc/main.rs: The entry point and main loop of the shell.src/parse.rs: Logic for parsing command-line input and handling quotes.src/commands/: Individual modules for each built-in command (ls,cd,echo, etc.).