Home - SayehHiba/Unix-Command-Interpreter GitHub Wiki

By Eya Karaa and Sayeh Hiba

English

The project is divided into two parts, so we have given the possibility to the user to choose the part they want to test through a menu.

1

  • Part 1: A simplified UNIX command interpreter

The ultimate goal of this part is to implement a simplified Unix command interpreter using C. This interpreter offer the possibility to:

-Read and write environment variables.

-Navigate into the file system and create alias.

-Interactively execute commands related to the PATH environment variable.

-Redirect the input / output of the executed commands.

-Read commands from a file.

-> We started by testing commands that were essential when working with a LINUX system:

**pwd **

3

** ls**

5

** mkdir**

7

rmdir

9

** rm**

10

** cat**

11

** tee**

12

** ps**

13

** wc**

14 15

The purpose of this part is to recover the user's working directory. By running the interpreter, read a ".txt" file that we have called "profile" and where we have configured the environment variables "PATH" and "HOME" which will subsequently be used by the interpreter.

Path E: / MiniSE | E: / MiniSE / other | E: / MiniSE / other / internal Home E: / SE

These last two lines are used to position the working directory of the user having launched the interpreter to E: / SE and also set the list of directories in which it search in the following order: E: / MiniSE, E: / MiniSE / other and E: / MiniSE / other / internal.

In fact, in order to check the existence of the two variables in the profile file, it is necessary to proceed from the following way:

-For the "Home" environment variable: you must extract all the part that begins with the character which is at position 6.

-For the "PATH" environment variable:

1 / It is necessary to extract all the part which begins with the character which is at the position n ° 6.

2 / Create a table that will contain all the directories mentioned in the environment variable "PATH" and whose existence must be verified in the "profile" file. To determine these directories, you must extract all the characters of the character string extracted in step 1 / until reaching the character ‘|’. Repeat this step until you reach the end of the chain characters.

-> In the event that one of the two environment variables is not set in the "profile" file, the interpreter will display an error message.

1 2 3

Shell navigation in the file system and creation of aliases

16 17 18 19 20 21

Execution of commands relating to the environment variable "PATH"

22 23

Redirection of I / O of executed commands

4 24 25 26 27 28

Reading a series of commands from a file

29 30 31

  • Part 2 : scheduling algorithms

FIFO without preemption

32 33

round robin

34 34

Shortest job first

35 36

Priority

37 38

Français

Le projet est divisé en deux parties, nous avons donc donné la possibilité à l’utilisateur de choisir la partie qu’il veut tester grâce à un menu.

1

  • Partie 1 : Un interpréteur de commandes UNIX simplifié

L’objectif ultime de cette partie est d’implémenter un interpréteur de commandes Unix simplifié en C. Cet interpréteur permettra de :

-Lire et écrire des variables d’environnement.

-Naviguer dans le système de fichier et créer des alias.

-Exécuter de manière interactive des commandes relatives à la variable d’environnement PATH.

-Rediriger les entrées/sorties de commandes exécutées.

-Lire des commandes depuis un fichier.

-> Nous avons commencé par tester des commandes indispensables lors de la manipulation d’un système LINUX.

**pwd **

3

** ls**

5

** mkdir**

7

rmdir

9

** rm**

10

** cat**

11

** tee**

12

** ps**

13

** wc**

14 15

Le but de cette partie est de récupérer le répertoire de travail de l’utilisateur. En exécutant l’interpréteur, lire un fichier ".txt" que nous avons appelé « profile » et où nous avons configuré les variables d’environnement « PATH » et « HOME » qui seront par la suite utilisées par l’interpréteur.

Path E: / MiniSE | E: / MiniSE / other | E: / MiniSE / other / internal Home E: / SE

Ces deux dernières lignes permettent de positionner le répertoire de travail de l’utilisateur ayant lancé l’interpréteur à E:/SE et de positionner aussi la liste des répertoires dans lesquels il recherche dans l’ordre suivant E:/MiniSE, E:/MiniSE/autre et E:/MiniSE/autre/interne.

En effet afin de vérifier l’existence des deux variables dans le fichier profile il faut procéder de la façon suivante :

-Pour la variable d’environnement « Home » : il faut extraire toute la partie qui commence par le caractère qui est à la position n°6.

-Pour la variable d’environnement « PATH » :

1/ Il faut extraire toute la partie qui commence par le caractère qui est à la position n°6.

2/ Créer un tableau qui contiendra tous les répertoires mentionnés dans la variable d’environnement « PATH » et dont il faut vérifier l’existence dans le fichier « profile ». Pour déterminer ces répertoires, il faut extraire tous les caractères de la chaine de caractères extraite dans l’étape 1/ jusqu’à atteindre le caractère ‘|’. Refaire cette étape jusqu’à atteindre la fin de la chaine de caractères.

-> In case one of the two environment variables is not set in the "profile" file, the interpreter will display an error message.

1 2 3

Navigation du Shell dans le système de ficher et création d’alias

16 17 18 19 20 21

Exécution de commandes relatives à la variable d’environnement « PATH »

22 23

Redirection des entrées/sorties des commandes exécutées

4 24 25 26 27 28

Lecture d’une suite de commandes depuis un fichier

29 30 31

  • Part 2 : Algorithmes d'ordonnoncement

FIFO sans préemption

32 33

Tourniquet (round robin)

34 34

Shortest job first

35 36

Priorité

37 38