Giter Club home page Giter Club logo

minibash's Introduction

minibash

Project overview:

This project consists of creating a shell that implements some of the functionalities present in bash.

The project was developed by me and Vitor Marcondes.

Features that will be implemented:

  • Working prompt, with history;
  • Search and launch executables by using the PATH variable or by using a relative or an absolute path;
  • Handle closed single or double quotes;
  • Handle the following redirections: < << > >>;
  • Handle pipes (| character);
  • Handle environment variables ($ character followed by their name);
  • Handle ctrl-C ctrl-D and ctrl-\;
  • Update the exit status of the commands;
  • The following built-ins:
  1. echo(with option -n);
  2. cd;
  3. pwd export unset exit(with no options);
  4. env (with no options or arguments).

Features that will NOT be implemented:

  • Handling of unclosed quotes;
  • handling of the following special characters: \ ; || && *.

Project approach:

In this project, we started by studying the bash program and how it behaved when using the features we were going to implement. Afterwards, we divided the project into 6 parts:

  • Prompt displaying;
  • Input parsing;
  • Signal handling;
  • Environment variables;
  • Built-in commands
  • Command execution.

Prompt displaying:

For prompt displaying we used the readline function from the GNU readline library which has inumerous functionalities. We used it to have a working history, handle ctrl-D and manipulate the prompt.

Input parsing:

Here is where we commited a mistake in the project approach. We decided to parse the prompt by doing string manipulation instead of tokenizing the words and symbols. This works fine, but it makes us loop through the input string several times manipulating different elements of the string each time, and it would also make it harder to add new symbols to be interpreted by the parser. If we were to do it again, we'd take the tokenization route.

Signal handling

The singal handling part was pretty straight forward. We used the sigaction function to create the handler for ctrl-c(SIGINT) and ignored ctrl-\(SIGQUIT). When handling the SIGINT signal we used some of the readline functions and variables. to manipulate the program behavior and the exit status value.

Environment variables:

For handling Environment variables we exported the environ variable and created a copy of it, this way we could manipulate the environment variables of our shell freely without messing with those of the shell that ran ours. We decided to copy it into a linked list so that it'd be easier to add, remove and change the contents of the environment variables.

Built-in commands:

The built-in commands were pretty straight foreward aswell, we read their documentation and implemented their behavior and error handling. For the built-ins that dealt with environment variables, we used the copy of environ that we created.

Command execution:

For the command execution we used function calls for the built-in commands and the fork function combined with the execve function for the executables. To implement the pipeline of commands we used the pipe function and to extract the exit status of the child processes we used the status parameter of the waitpid function.

Executing the program:

Platforms supported: Linux and Macos.

To try it out follow these simple steps:

Extra step for macos users:

If you are using macos you will need to install the readline library. You can do it through homebrew by runnig the following:

brew install readline

1 Clone this repository wherever you like:

git clone https://github.com/gabrielclcardoso/minibash

2 Enter the cloned repository and run make inside it:

cd minibash && make

3 Run the minibash executable and prompt away :)

./minibash

minibash's People

Contributors

itsmevitinn avatar gabrielclcardoso 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.