Skip to content

Unix-v6-like shell written in Rust

License

Notifications You must be signed in to change notification settings

bassosimone/xv6sh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unix-v6-like shell written in Rust

This repository contains a Unix-v6-like shell implemented in Rust.

I wrote this code to exercise with Rust. I do not plan on maintaining this code base or on adding additional features. It's likely the case that this code behaves differently from the original v6 shell.

Building and running

You need rustc and cargo (possibly via rustup).

To build:

cargo build

To run:

cargo run

Design

The design is quite traditional for a compiler-like tool:

  1. there is a lexer (see src/lexer.rs) that implements the scan stage;

  2. the lexer feeds a parser (see src/parser.rs), which produces a parse tree in the parse stage;

  3. we validate the parse tree and transform it for easier execution (see src/translator.rs) in the plan stage;

  4. we interpret the transformed output (see src/interp.rs) to execute shell commands in the run stage.

When we encounter commands between ( and ) we execute them in a subshell. We pass code to the subshell by serializing the specific portion of the parse tree using src/serializer.rs.

Command Line Flags

The -x command line flag prints each command before it's executed.

The --stage STAGE flag stops processing at the given STAGE and shows internal data structures.

The -c COMMANDS command allows a shell (or a sub-shell) to execute a sequence of commands.

License

See mit-pdos/xv6-riscv's sh.c for the source code that I started from. The implementation diverged quickly but there are still original-code ideas. For this reason, the copyright is the original one plus mine.

SPDX-License-Identifier: MIT

About

Unix-v6-like shell written in Rust

Resources

License

Stars

Watchers

Forks

Languages