A minimalist Unix-like shell implemented in Rust, designed to execute core Unix commands using system calls without relying on external binaries or built-in shells like bash
or sh
. Inspired by tools like BusyBox, 0-Shell is built for an embedded Linux environment, emphasizing lightweight design, safety, and direct interaction with Unix system APIs.
- Overview
- Features
- Requirements
- Installation
- Usage
- Supported Commands
- Constraints
- Contributing
- License
0-Shell is a system-level project that introduces developers to Unix system programming through Rust's safe and efficient abstractions. It focuses on core shell functionalities, including process creation, command execution, and file system interaction, without depending on external utilities. The shell is designed to mimic essential Unix shell behaviors while adhering to good coding practices and robust error handling.
- Displays a prompt in the format
~/path/to/current/directory $
for user input - Parses and executes basic Unix commands
- Maintains a command history accessible via the
history
command - Clears the terminal screen with the
clear
command - Handles
Ctrl+D
(EOF) andCtrl+C
gracefully to exit or interrupt without crashing - Implements commands using Rust and system calls, avoiding external binaries
- Provides clear error messages for unrecognized commands
- Supports basic command-line arguments for specific commands (e.g.,
ls -l
,ls -a
,-F
)
- Rust (stable, version 1.82.0 or higher recommended)
- Cargo (Rust's package manager)
- A Unix-like operating system (Linux recommended)
- Basic familiarity with Unix commands and Rust programming
-
Clone the Repository:
git clone https://github.com/yourusername/0-shell.git cd 0-shell
-
Build the Project:
cargo build
-
Launch the shell by running:
cargo run
-
At the
~/path/to/current/directory $
prompt, enter a command (e.g.,ls
,cd dir_name
,echo hello
). -
Use
Ctrl+D
or typeexit
to quit the shell, orCtrl+C
to interrupt the current operation without crashing. -
If an unrecognized command is entered, the shell will display:
Command '<name>' not found
The following commands are implemented from scratch using Rust and system calls:
echo
: Prints text to the consolecd
: Changes the current working directoryls
: Lists directory contents (supports-l
,-a
,-F
flags)pwd
: Prints the current working directorycat
: Displays file contentscp
: Copies filesrm
: Removes files (supports-r
for recursive deletion)mv
: Moves or renames filesmkdir
: Creates directoriesclear
: Clears the terminal screenhistory
: Displays the history of entered commandsexit
: Exits the shell
- Supports only basic command syntax (no piping, redirection, or globbing or ...)
- Commands are implemented without relying on external binaries
- Shell behavior aligns with Unix conventions
- Code adheres to Rust's safety guarantees and best practices