Coder Social home page Coder Social logo

magalhaesm / minishell Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 1.0 262 KB

This project is about creating a simple shell.

License: GNU General Public License v3.0

Makefile 3.62% C 96.38%
42saopaulo 42school 42sp c ecole42 makefile minishell minishell-42 minishell42

minishell's Introduction

OS Language Grade Status

Introduction

The 8th project of 42 cursus syllabus asks students to implement a simplified shell. It's about minishell, as beautiful as a shell.

As the project's subject states, the existence of shells is linked to the very existence of IT. At the time, all developers agreed that communicating with a computer using aligned 1/0 swiches was seriously irritating. It was only logical that they came up with the idea of creating a software to communicate with a computer using interactive lines of commands in a language somewhat close to the human language.

How to compile and run the project

1) Copy this repository to your local workstation

git clone https://github.com/magalhaesm/minishell.git

2) Install the required libraries to run the functions from readline library

sudo apt-get install -y libreadline6 libreadline6-dev

3) Compile the project with Makefile

make

4) Launch the executable file

./minishell

If you want to run the executable program automatically with valgrind flags to check for leaks, just write make checks and press enter.

Implemented builtins

Builtin Command description
echo with -n Displays a line of text to the standard output
cd Changes the working directory of the current shell execution environment
pwd Prints the full filename of the current working directory
export name[=word] Sets the export attribute for variables
unset Unsets values and attributes of variables and functions
env Sets each name to value in the enviroment and run command
exit Causes the shell to exit with exit status specified

About how we implemented the project

There are two main files at projects's root directory:

  • include: contains all the necessary headers for the project
  • grammar: the implemented grammar, which creates and checks the sentences
  • libft: our own C library with some helpful auxiliary functions, such as ft_strlen
  • tests: contains unit tests created with Criterion testing framework to evaluate functions in src
  • src: contains the whole project implementation
    • builtins: implements the required builtins by the project's subject
    • exec: consists of functions that executes user's input
    • expansion: implements shell expansors, such as quote marks and wildcards
    • helpers: contains utils function used on the project as a whole
    • parser: consists of functions that implement the minishell's grammar and create a tree of a given input by the user
    • scanner: implements a scanner to create tokens of a given input by the user
    • signals: consists of functions that handle user events, such as ctrl-C, ctrl-D and ctrl-\
    • table: implements a hash table to store enviroment variables

Project flowchart

In a nutshell, the project flowchart is as follows:

graph LR;
    INPUT-->scanner;
    scanner-->parser;
    parser-->expansor;
    expansor-->executor;
    executor-->OUTPUT

As an example, if given the input true && ls || echo the program generates the tree below to be executed:

graph TD;
    OR-->AND;
    OR-->echo;
    AND-->true;
    AND-->ls;

References

minishell's People

Contributors

magalhaesm avatar ygor-sena avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ygor-sena

minishell's Issues

Invalid read of length 1 when it has unmatched strings

Problem found while looking for leaks.

==5169== Invalid read of size 1
==5169==    at 0x109E19: is_at_end (scanner_utils.c:47)
==5169==    by 0x109F87: string (token_word.c:43)
==5169==    by 0x109EB9: token_word (token_word.c:29)
==5169==    by 0x109CB0: scan_double_char_token (scanner.c:66)
==5169==    by 0x109B2D: scan_token (scanner.c:38)
==5169==    by 0x109332: print_tokens (minishell.c:47)
==5169==    by 0x10926F: main (minishell.c:30)

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.