Code Monkey home page Code Monkey logo

simple_shell's Introduction

Simple Shell

Run a shell designed to mimic sh. Execute commands and interact with the kernel.

simplesh [script files]

Current features

  • Run commands in $PATH
  • Environment and local variables
  • $? return values, $$ pid
  • $# number of args and $0-9 (not a perfect sh mimic currently though)
  • Logical operators &&/|| with multi-line continuation
  • ; command separator
  • ~ expansion to current user's home directory
  • unclosed multi-line quote continuation
  • \ escaping
  • Run script files, as well as commands from standard input

Built-ins:

  • help
  • exit [status]
  • setenv
  • unsetenv
  • env (listing environment functionality only)
  • cd
  • alias
  • unalias
  • history

Getting started

To use this shell, we want to compile it and move it into a $PATH folder like /usr/local/bin. To compile the program, clone the project, navigate to the directory, and then type:

gcc -o simplesh *.c

The copy the output file to /usr/local/bin (you may need to add "sudo" to the front of this line):

cp simplesh /usr/local/bin

After this you should be able to run the shell by typing "simplesh".

Usage Examples

To start up the shell and run a simple command (in this case pwd), then exit:

Username@your-regular-prompt:~$ simplesh
simplesh:/home/username$ pwd
/home/username/
simplesh:/home/username$ exit
Username@your-regular-prompt:~$

pwd lists the current working directory, which is displayed in the simplesh terminal prompt. We can also run script files. If we have a script with the following:

#!/usr/bin/env simplesh
echo Hello from simple shell!

Then execute the script we will see "Hello from simple shell!" in our terminal. We can also use command line arguments for variables. Currently, $0 is always "simplesh", $1 is the script name, and $2 and beyond are the arguments. So if we want the first argument, we would put in $2 like so:

#!/usr/bin/env simplesh
echo Hello $2

Then if we want to pass in an argument we can do it like so:

Username@your-regular-prompt:~$ ./helloscript "simple shell!"
Hello simple shell!

Testing

There is a repository for the test suite at https://github.com/sidneyriffic/shelltest.git. Follow the instructions there, and you'll want the shell target to be /bin/sh (the default location for sh).

Authors

Sidney Burkett
Gregory Dame

simple_shell's People

Contributors

sidneyriffic avatar gjdame avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.