|
1 | | -## 0-shell |
| 1 | +## 0-Shell |
2 | 2 |
|
3 | | -### Objective |
| 3 | +### Overview |
4 | 4 |
|
5 | | -The objective of this project is for you to create a simple [shell](https://en.wikipedia.org/wiki/Unix_shell). |
| 5 | +In this project, you'll build **0-shell**, a minimalist Unix-like shell implemented in **Rust**, designed to run core Unix commands using system calls—without relying on external binaries or built-in shells like `bash` or `sh`. |
6 | 6 |
|
7 | | -Through the `0-shell` you will get to the core of the `Unix` system and explore an important part of this system’s API which is the process creation and synchronization. |
8 | | -Executing a command inside a shell implies creating a new process, which execution and final state will be monitored by its parents processes. This set of functions will be the key to success for your project. |
| 7 | +Inspired by tools like [BusyBox](https://en.wikipedia.org/wiki/BusyBox), this project introduces you to key concepts in **Unix system programming**, including **process creation**, **command execution**, and **file system interaction**, all while leveraging Rust's safety and abstraction features to avoid manual memory management. |
9 | 8 |
|
10 | | -For this project you will only have to create a simple `Unix shell` where you can run some of the most known commands. For this part of the project, no advanced functions, pipes or redirection will be asked, but you can add them if you like. |
| 9 | +### Role Play |
11 | 10 |
|
12 | | -### Instructions |
| 11 | +You are a **system-level developer** assigned to build a lightweight, standalone Unix shell for an embedded Linux environment. Your task is to create a shell that handles basic navigation, file manipulation, and process control—faithfully mimicking essential shell behaviors without relying on existing shell utilities. |
13 | 12 |
|
14 | | -- You must program a mini `Unix shell`, try to focus on something simple like [BusyBox](https://en.wikipedia.org/wiki/BusyBox). |
15 | | -- This interpreter must display at least a simple `$` and wait until you type a command line which will be validated by pressing enter. |
16 | | -- The `$` will be shown again only once the command has been completely executed. |
17 | | -- The command lines are simple, you will not have pipes, redirection or any other advanced functions. |
18 | | -- You must manage the errors, by displaying a message adapted to the error output. |
19 | | -- You must implement the following commands: |
20 | | - - `echo` |
21 | | - - `cd` |
22 | | - - `ls`, including the flags `-l`, `-a` and `-F` |
23 | | - - `pwd` |
24 | | - - `cat` |
25 | | - - `cp` |
26 | | - - `rm`, including the flag `-r` |
27 | | - - `mv` |
28 | | - - `mkdir` |
29 | | - - `exit` |
| 13 | +### Learning Objectives |
30 | 14 |
|
31 | | -> The commands need to be implemented from scratch, without calling any external binaries. |
| 15 | +- Work with **file and directory operations** |
| 16 | +- Manage **user input and output** within a shell loop |
| 17 | +- Implement **robust error handling** |
| 18 | +- Gain experience in **Unix process and system call APIs** |
32 | 19 |
|
33 | | -- You must manage the program interruption `Ctrl + D`. |
34 | | -- The project has to be written in a compiled language (like C, Rust, Go or other), **interpreted languages (like Perl and others) are not allowed**. |
35 | | -- The code must respect the [good practices](https://public.01-edu.org/subjects/good-practices/) |
| 20 | +### Core Requirements |
36 | 21 |
|
37 | | -This project will help you learn about: |
| 22 | +Your minimalist shell must: |
38 | 23 |
|
39 | | -- Shell |
40 | | -- Operating systems services |
41 | | -- Command-line interfaces |
42 | | -- Unix system |
43 | | -- Process creation and synchronization |
44 | | -- Commands syntax |
45 | | -- Scripting language |
| 24 | +- Display a prompt (`$ `) and wait for user input |
| 25 | +- Parse and execute user commands |
| 26 | +- Return to the prompt only after command execution completes |
| 27 | +- Handle `Ctrl+D` (EOF) gracefully to exit the shell |
46 | 28 |
|
47 | | -### Bonus |
| 29 | +You must implement the following commands **from scratch**, using system-level Rust abstractions: |
48 | 30 |
|
49 | | -You can also do more bonus features like: |
| 31 | +- `echo` |
| 32 | +- `cd` |
| 33 | +- `ls` (supporting `-l`, `-a`, `-F`) |
| 34 | +- `pwd` |
| 35 | +- `cat` |
| 36 | +- `cp` |
| 37 | +- `rm` (supporting `-r`) |
| 38 | +- `mv` |
| 39 | +- `mkdir` |
| 40 | +- `exit` |
50 | 41 |
|
51 | | -- Implement the commands exclusively using `low-level system calls` avoiding built-in functions or libraries that abstract file operations. |
| 42 | +Additional constraints: |
52 | 43 |
|
53 | | - - Avoid High-Level Abstractions: Instead of using functions like the Go `os.Open, os.Remove, and io.Copy`, you would use system calls directly through the `syscall` package using `syscall.Open, syscall.Close, syscall.Read, syscall.Write, syscall.Unlink`. |
| 44 | +- Do **not** use any external binaries or system calls that spawn them |
| 45 | +- If a command is unrecognized, print: |
| 46 | + `Command '<name>' not found` |
54 | 47 |
|
55 | | -- Manage the interruption `Ctrl + C` |
56 | | -- Auto complete when you are writing |
57 | | -- Add piping |
58 | | -- Add redirection |
59 | | -- Have your path behind the `$` like (~/Desktop/0-shell $) |
60 | | -- Add colors for the directories or errors |
61 | | -- Other advanced commands you may like. |
| 48 | +### Constraints |
62 | 49 |
|
63 | | -### Usage |
| 50 | +- Only basic command syntax is required |
| 51 | + (No piping `|`, no redirection `>`, no globbing `*`, etc.) |
| 52 | +- Shell behavior should align with Unix conventions |
| 53 | +- Code must follow [good coding practices](https://public.01-edu.org/subjects/good-practices/) |
64 | 54 |
|
65 | | -``` |
| 55 | +### Bonus Features |
| 56 | + |
| 57 | +Implementing any of the following will be considered bonus: |
| 58 | + |
| 59 | +- Handle `Ctrl+C` (SIGINT) without crashing the shell |
| 60 | +- Shell usability enhancements: |
| 61 | + - **Auto-completion** |
| 62 | + - **Command history** |
| 63 | + - **Prompt with current directory** (e.g., `~/projects/0-shell $`) |
| 64 | + - **Colorized output** for commands, directories, and errors |
| 65 | + - **Command chaining** with `;` |
| 66 | + - **Pipes** (`|`) |
| 67 | + - **I/O redirection** (`>`, `<`) |
| 68 | +- Support for environment variables (e.g. `$HOME`, `$PATH`) |
| 69 | +- A custom `help` command documenting built-in functionality |
| 70 | + |
| 71 | +### Example Usage |
| 72 | + |
| 73 | +```shell |
66 | 74 | student$ ./0-shell |
67 | 75 | $ cd dev |
68 | 76 | $ pwd |
69 | | -dev |
| 77 | +/dev |
70 | 78 | $ ls -l |
71 | 79 | total 0 |
72 | | -crw------- 1 root root 10, 58 fev 5 09:21 acpi_thermal_rel |
73 | | -crw-r--r-- 1 root root 10, 235 fev 5 09:21 autofs |
74 | | -drwxr-xr-x 2 root root 540 fev 5 09:21 block |
75 | | -crw------- 1 root root 10, 234 fev 5 09:21 btrfs-control |
76 | | -drwxr-xr-x 3 root root 60 fev 5 09:20 bus |
77 | | -drwxr-xr-x 2 root root 4400 fev 5 09:21 char |
78 | | -crw------- 1 root root 5, 1 fev 5 09:21 console |
79 | | -lrwxrwxrwx 1 root root 11 fev 5 09:20 core -> /proc/kcore |
80 | | -drwxr-xr-x 2 root root 60 fev 5 09:20 cpu |
81 | | -crw------- 1 root root 10, 59 fev 5 09:21 cpu_dma_latency |
| 80 | +crw------- 1 root root 10, 58 Feb 5 09:21 acpi_thermal_rel |
| 81 | +crw-r--r-- 1 root root 10, 235 Feb 5 09:21 autofs |
| 82 | +drwxr-xr-x 2 root root 540 Feb 5 09:21 block |
| 83 | +... |
82 | 84 | $ something |
83 | 85 | Command 'something' not found |
84 | 86 | $ echo "Hello There" |
85 | 87 | Hello There |
86 | 88 | $ exit |
87 | 89 | student$ |
88 | 90 | ``` |
| 91 | + |
| 92 | +### Evaluation Criteria |
| 93 | + |
| 94 | +This project will be reviewed and graded based on the following: |
| 95 | + |
| 96 | +- **Functionality**: Commands perform correctly and emulate standard Unix behavior |
| 97 | +- **Stability**: Shell handles user errors, invalid input, and edge cases without crashing |
| 98 | + |
| 99 | +### Resources |
| 100 | + |
| 101 | +- [man pages](https://man7.org/linux/man-pages/) (e.g., `man 2 open`, `man 2 execve`) |
| 102 | +- [Unix Shell - Wikipedia](https://en.wikipedia.org/wiki/Unix_shell) |
| 103 | +- [BusyBox](https://busybox.net/) |
| 104 | +- [Rust std::fs and std::process Docs](https://doc.rust-lang.org/std/) |
0 commit comments