Writing a shell program in Rust (project)
We learned in the Delving into Linux process fundamentals section what a shell program is. In this section, let's build a shell program, adding features iteratively.
In the first iteration, we'll write the basic code to read a shell command from the command line and spawn a child process to execute the command. Next, we'll add the ability to pass command arguments to the child process. Lastly, we will personalize the shell by adding support for users to enter commands in a more natural-language-like syntax. We'll also introduce error handling in this last iteration. Let's get started:
- Let's first create a new project:
cargo new myshell && cd myshell
- Create three files:
src/iter1.rs
,src/iter2.rs
, andsrc/iter3.rs
. The code for the three iterations will be placed in these files so that it will be easy to build and test each iteration separately. - Add the following to
Cargo.toml
:[[bin]]...