Skip to content

42elenz/42_minishell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

minishell

This shell was done as a group project with afrasch at the school 42Heilbronn.

Welcome to our "SHELL SHOCK" Minishell. Handling all the minor cases creating a shell like expanding, Here-Docs and all the other things we had to take of really gave us a little Shell-Shock :D

Image scroe

Contents

Short description of the subject

The goal of the subject was to recreate some of the functionalities of bash (Version 3.2).
To see the exact requirements, check Chapter III and IV of the subject pdf.

From the subject pdf

Introduction

Creating our own shell is a task to bring us back and let us face the problems that people had back in the days.

Some of the restrictions

subject_restrictions

Our Minishell

The basic functionalities of the project

  • this is a shell that can be compiled by running
    make all
    and then to run it
    ./minishell
  • now you are greeted with a prompt waiting for input just like any other shell
  • this project uses the readline libraries readline/history.h and readline/readline.h you can install those via brew install readline or apt-get install libreadline-dev, thanks to those there is a working history of used commands
  • there is some memory-leaks caused by the readline-library

Here is an example of a basic command executed in our shell: Image scroe

The basic structure of our minishell

Just like most of the other shells we have divided our shell into 3 parts:

  1. Lexer and Parser
  2. Expander
  3. Executor

Those parts all have different tasks.


Lexer and Parser

In our minishell the lexer and parser are combined. We build the tokens as so called "chunks" and to save computing
we also parse. Some basic expensions are also done in this step. We decieded to use this design despite of what other shells
usually do due to the lesser functionalities of our programm. back to contents
back to basic structure


Expander

The expander will take the parser tokens as argument.
The expander will interprete the environment variables into their corresponding value.
It also handles subshells, creates pipes and handles all the opening of input-/output-redirections and storing the correct ones in the executor tokens.
Subshells are executed by creating a child process which runs minishell without readline reading the input, but directly handing the correct, unparsed commands to it. And after the lexer is done, it will call the parser and so on.
After passing every of those parts without errors, it calls the executor in a loop and gives the executor the correct values to work with.
After a call of the executor, an error value, similar to errno, is set to the exit code of the executor.
This error value can be checked by running echo $? and is used for the && and || logic.

This is the way the data is stored in the expander tokens and handed to the executor:

back to contents
back to basic structure


Executor

The executor does as it is called, it executes the command.
If the given command is an inbuilt, it will just run the command in the same process, if it isn't it will create a child process to run the command in.
After this is decided, the redirections of input and output are done and the command is executed.
The executor always returns the exit code of whatever it did.

back to contents
back to basic structure


Some example outputs

wrong syntax

If some form of wrong syntax gets detected, Invalid Syntax at token is printed and the error value $? is set to 258
syntax_error

invalid command

If there was an invalid command used, command not found is printed and the error value $? is set to 127
invalid_command
back to contents

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published