Skip to content

Latest commit

 

History

History
131 lines (97 loc) · 5.8 KB

README.md

File metadata and controls

131 lines (97 loc) · 5.8 KB

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
Loading

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;
Loading

References