Skip to content

snarang181/sam-sh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sam_sh

Video Presentation Link

https://drive.google.com/file/d/1Pd3R7W3v1AcFUElWukNw7PeVFilctPrM/view

Description

sam_sh is a program written in the Rust programming language. It is a basic shell wrapper program that can execute built in shell commands and also support piping of multiple commands. It also supports the following built in commands:

  1. ls - List files and directories in the current working directory.
  2. clear - Clear the terminal screen.
  3. grep - Search for a pattern in a file.
  4. touch - Create a new file.
  5. rm - Remove a file.
  6. cat - Display the contents of a file.
  7. bash - Execute a bash script.

Design

The program loops infinitely and waits for user input. Then, the parsing of the user input is done and the next steps depend on the type of command. If the command is exit or quit, the loop is broken and the program ends. In other cases, we check if the user input has a pipe ( | ) in their command. If no pipe exists, the bash built in command is executed by Rust's Command module. If a pipe exists, the user input is split by the piped commands and an iterator is created. Then, the first command is executed and the output is piped to the next command. This process is repeated until all the commands are executed.

Example Usage

  1. Execute a bash script

sam_sh> vi test_bash.sh

A Vim editor should open up and enter the following in the file:

#!/bin/bash
echo "Hello World"

sam_sh> bash test_bash.sh

See the following output:

Hello World
  1. List files and directories in the current working directory
    sam_sh> ls

See the following output:

Cargo.lock      Cargo.toml      README.md       src             target  
  1. Use piping to execute multiple commands

a. sam_sh> ls -laF | grep Cargo

See the following output:

-rw-r--r--   1 samarthnarang  staff   152 Apr 13 18:27 Cargo.lock
-rw-r--r--   1 samarthnarang  staff   177 Apr 13 18:23 Cargo.toml

b. sam_sh> ls -laF | grep Cargo | tail -n 1

See the following output:

-rw-r--r--   1 samarthnarang  staff   177 Apr 13 18:23 Cargo.toml

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages