The objective of this project is for you to create a simple [shell](https://en.wikipedia.org/wiki/Unix_shell).
The objective of this project is for you to create a simple [shell](https://en.wikipedia.org/wiki/Unix_shell).
Through the `0-shell` you will get to the core of the `Unix` system and explore an important part of this system’s API witch is the process creation and synchronization.
Through the `0-shell` you will get to the core of the `Unix` system and explore an important part of this system’s API which is the process creation and synchronization.
Executing a command inside a shell implies creating a new process, which execution and final state will be monitored by its parents process. This set of functions will be the key to success for your project.
Executing a command inside a shell implies creating a new process, which execution and final state will be monitored by its parents processes. This set of functions will be the key to success for your project.
For this project you will only have to create a simple `Unix shell` where you can run some of the most known commands. For this part of the project, no advanced functions, pipes or redirection will be asked, you can add them if you like.
For this project you will only have to create a simple `Unix shell` where you can run some of the most known commands. For this part of the project, no advanced functions, pipes or redirection will be asked, but you can add them if you like.
### Instructions
### Instructions
- You must program a mini `Unix shell`, try to focus on something simple like [BusyBox](https://en.wikipedia.org/wiki/BusyBox).
- You must program a mini `Unix shell`, try to focus on something simple like [BusyBox](https://en.wikipedia.org/wiki/BusyBox).
- This interpreter must display at least a simple `$` and wait until you type a command line witch will be validated by pressing enter.
- This interpreter must display at least a simple `$` and wait until you type a command line which will be validated by pressing enter.
- The `$` will be shown again only once the command has been completely executed.
- The `$` will be shown again only once the command has been completely executed.
- The command lines are simple, you will not have pipes, redirection or any other advanced functions.
- The command lines are simple, you will not have pipes, redirection or any other advanced functions.
- You must manage the errors, by displaying a message adapted to the error output.
- You must manage the errors, by displaying a message adapted to the error output.
@ -28,7 +28,7 @@ For this project you will only have to create a simple `Unix shell` where you ca
- mkdir
- mkdir
- exit
- exit
- You must manage the program interruption `Ctrl + D`.
- You must manage the program interruption `Ctrl + D`.
- The project has to be written in a compiled language like (C, Rust, Go or other), no interpreted languages like (Perl and others) are allowed.
- The project has to be written in a compiled language like (C, Rust, Go or other), **interpreted languages like (Perl and others) are not allowed**.
- The code must respect the [good practices](https://public.01-edu.org/subjects/good-practices/)
- The code must respect the [good practices](https://public.01-edu.org/subjects/good-practices/)
###### Can you confirm that this interpreter displays at least a simple `$` and waits for you to type a command?
###### Can you confirm that this interpreter displays at least a simple `$` and waits for you to type a command?
##### Try to run a command at your choice.
##### Try to run a command of your choice.
###### Can you confirm that the interpreter only validates the command if you type enter?
###### Can you confirm that the interpreter only validates the command if you press enter?
##### Try to run the command `"exit"`.
##### Try to run the command `"exit"`.
@ -32,11 +32,11 @@
###### Can you confirm that the interpreter displayed the current path?
###### Can you confirm that the interpreter displayed the current path?
##### Try to open the project and create a parent folder with two child folders using the command "mkdir". Then enter the parent folder and do "pwd".
##### Try to open the project and create a parent folder with two children folders using the command "mkdir". Then enter the parent folder and do "pwd".
###### Can you confirm that the interpreter displayed the current path?
###### Can you confirm that the interpreter displayed the current path?
##### Try to enter a directory at your choice by using the command `"cd dir/at/your/choice"`.
##### Try to enter a directory of your choice by using the command `"cd dir/of/your/choice"`.
###### Can you confirm that the interpreter took you to the correct path? Use `"pwd"` to confirm.
###### Can you confirm that the interpreter took you to the correct path? Use `"pwd"` to confirm.
@ -52,7 +52,7 @@
###### Can you confirm that the output is the same in the project and in your computer terminal?
###### Can you confirm that the output is the same in the project and in your computer terminal?
##### Try to run the commands `"mkdir new_folder1"` and `"mkdir new_folder2"` in a directory at your choice.
##### Try to run the commands `"mkdir new_folder1"` and `"mkdir new_folder2"` in a directory of your choice.
###### Can you confirm that the directory `new_folder1` and `new_folder2` were created?
###### Can you confirm that the directory `new_folder1` and `new_folder2` were created?
###### Can you confirm that the program displayed a list with the status of all jobs like the example above?
###### Can you confirm that the program displayed a list with the status of all jobs like in the example above?
##### Try to run the command `"jobs -l"`.
##### Try to run the command `"jobs -l"`.
@ -18,7 +18,7 @@
[1]+ 13612 Running tar -czf home.tar.gz . &
[1]+ 13612 Running tar -czf home.tar.gz . &
```
```
###### Can you confirm that the program added the process ID to the normal information given in the command `"jobs"` like the example above?
###### Can you confirm that the program added the process ID to the normal information given in the command `"jobs"` like in the example above?
##### Try to run the command `"jobs -p"`.
##### Try to run the command `"jobs -p"`.
@ -26,7 +26,7 @@
13612
13612
```
```
###### Can you confirm that the program only displays the process ID like the example above?
###### Can you confirm that the program only displays the process ID like in the example above?
##### Try to run the command `"sleep 50000 &"` then run `"python &"` and press enter without any input in the last command.
##### Try to run the command `"sleep 50000 &"` then run `"python &"` and press enter without any input in the last command.
@ -45,7 +45,7 @@
[2]- Running sleep 50000 &
[2]- Running sleep 50000 &
```
```
###### Can you confirm that the program only displays the list with running jobs like the example above?
###### Can you confirm that the program only displays the list with running jobs like in the example above?
##### Try to run the command `"jobs -s"`.
##### Try to run the command `"jobs -s"`.
@ -53,7 +53,7 @@
[3]+ Stopped python
[3]+ Stopped python
```
```
###### Can you confirm that the program only displays the list with stopped jobs like the example above?
###### Can you confirm that the program only displays the list with stopped jobs like in the example above?
##### Try to run the command `"kill 7764"`(the process ID must be yours this is just an example).
##### Try to run the command `"kill 7764"`(the process ID must be yours this is just an example).
@ -61,7 +61,7 @@
[2]- Terminated sleep 50000
[2]- Terminated sleep 50000
```
```
###### Can you confirm that the program killed and displayed the process with the given id like the example above?
###### Can you confirm that the program killed and displayed the process with the given id like in the example above?
##### Try to run the command `"kill %1"`.
##### Try to run the command `"kill %1"`.
@ -69,7 +69,7 @@
[1] Terminated tar -czf home.tar.gz
[1] Terminated tar -czf home.tar.gz
```
```
###### Can you confirm that the program killed and displayed the first process like the example above?
###### Can you confirm that the program killed and displayed the first process like in the example above?
##### Close the program and run it again. Try to run the commands `"tar -czf home.tar.gz . &"`, `"sleep 50000 &"` and then run `"fg"`.
##### Close the program and run it again. Try to run the commands `"tar -czf home.tar.gz . &"`, `"sleep 50000 &"` and then run `"fg"`.
@ -78,7 +78,7 @@ sleep 50000
```
```
###### Can you confirm that the program brings the background job to the foreground like the example above?
###### Can you confirm that the program brings the background job to the foreground like in the example above?
##### Try to run the command `"fg"` then stop the process with the `"Ctrl + Z"`.
##### Try to run the command `"fg"` then stop the process with the `"Ctrl + Z"`.
@ -88,7 +88,7 @@ sleep 50000
[2]+ Stopped sleep 50000
[2]+ Stopped sleep 50000
```
```
###### Can you confirm that the program brings the background job to the foreground and after you press `"Ctrl + Z"` the process stops like the example above?
###### Can you confirm that the program brings the background job to the foreground and after you press `"Ctrl + Z"` the process stops like in the example above?
##### Try to run the command `"bg"`.
##### Try to run the command `"bg"`.
@ -96,4 +96,4 @@ sleep 50000
[2]+ sleep 50000 &
[2]+ sleep 50000 &
```
```
###### Run `"jobs"`. Can you confirm that the program started the process in the background like the example above?
###### Run `"jobs"`. Can you confirm that the program started the process in the background like in the example above?
@ -8,9 +8,9 @@ In `scripting` you must find a way to make your `0-shell` run shell scripts.
By now you should be familiar with the basics in an interactive shell. Now your purpose is to learn how to put those commands together to create scripts and run them in your own interpreter.
By now you should be familiar with the basics in an interactive shell. Now your purpose is to learn how to put those commands together to create scripts and run them in your own interpreter.
Some examples of common scripting languages are [ash](https://en.wikipedia.org/wiki/Almquist_shell), [bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell)) and [dash](https://wiki.archlinux.org/index.php/Dash). But you can choose another one as long as it is a [Unix shell](https://en.wikipedia.org/wiki/Unix_shell).
Some examples of common scripting languages are [ash](https://en.wikipedia.org/wiki/Almquist_shell), [bash](<https://en.wikipedia.org/wiki/Bash_(Unix_shell)>) and [dash](https://wiki.archlinux.org/index.php/Dash). But you can choose another one as long as it is a [Unix shell](https://en.wikipedia.org/wiki/Unix_shell).
You will have to create your own valid script called `create-dir`. This script must be able to create a new directory by checking if it exists or not. So, you will have to run the script, where it will ask the user for a "Directory name", then the user will give a name to the directory that he wants to create and press enter. The script will check if the directory exists or not and if it does not exist, the directory will be created and the message "Directory created" will be displayed. If the directory already exists, nothing will be created and the message "Directory exist" will be displayed.
You will have to create your own valid script called `create-dir`. This script must be able to create a new directory by checking if it exists or not. So, you will have to run the script, where it will ask the user for a "Directory name", then the user will give a name of the directory that he wants to create and press enter. The script will check whether the directory exists or not, and if it does not exist, the directory will be created and the message "Directory created" will be displayed. If the directory already exists, nothing will be created and the message "Directory exist" will be displayed.
Your program must be able not just to run script files but also to run the scripts directly on the interpreter. For example, it must be able to pass for loops, functions, manipulate data etc...:
Your program must be able not just to run script files but also to run the scripts directly on the interpreter. For example, it must be able to pass for loops, functions, manipulate data etc...:
@ -30,7 +30,7 @@ myfunc() {
- You have to create your own script.
- You have to create your own script.
- The `0-shell` must be able to read and execute scripts.
- The `0-shell` must be able to read and execute scripts.
- The project has to be written in a compiled language like (C, Rust Go or other), no interpreted languages like (Pearl and others) are allowed.
- The project has to be written in a compiled language like (C, Rust Go or other), **interpreted languages like (Perl and others) are not allowed**.
- The code must respect the [good practices](https://public.01-edu.org/subjects/good-practices/)
- The code must respect the [good practices](https://public.01-edu.org/subjects/good-practices/)
###### Can you confirm that the script is valid and the directory "Example" was created like the example above?
###### Can you confirm that the script is valid and the directory "Example" was created like in the example above?
##### Try to run the student script in the `0-shell` interpreter and create the directory "Example1".
##### Try to run the student script in the `0-shell` interpreter and create the directory "Example1".
@ -24,7 +24,7 @@ Example1
Directory created
Directory created
```
```
###### Can you confirm that the script is valid and the directory "Example1" was created like the example above?
###### Can you confirm that the script is valid and the directory "Example1" was created like in the example above?
##### Try to run the student script in the `0-shell` interpreter and create the directory with the same name as before "Example1".
##### Try to run the student script in the `0-shell` interpreter and create the directory with the same name as before "Example1".
@ -34,7 +34,7 @@ Example1
Directory exist
Directory exist
```
```
###### Can you confirm that the directory was not created and the script shows the message "Directory exist" because a directory with that name already exists like the example above?
###### Can you confirm that the directory was not created and the script shows the message "Directory exist" because a directory with that name already exists like in the example above?
##### Try to run the command `"NAME="Alex""` followed by the command `"echo "Hello $NAME!""` in the `0-shell` interpreter.
##### Try to run the command `"NAME="Alex""` followed by the command `"echo "Hello $NAME!""` in the `0-shell` interpreter.