The objective of this project is for you to create a simple [shell](https://en.wikipedia.org/wiki/Shell_script).
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.
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.
For this project you will only have to create a simple `Unix` interpreter 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, you can add them if you like.
### Instructions
- You must program a mini `Unix` interpreter.
- 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.
- 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.
- You must manage the errors, by displaying a message adapted to the error output.
- You must implement the following commands that will behave exactly like the originals:
- You must implement the following commands:
- echo
- cd
- ls
@ -28,7 +28,7 @@ For this project you will only have to create a simple `Unix` interpreter where
- mkdir
- exit
- 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 semi compiled language like (Pearl and others) are allowed.
- 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 code must respect the [good practices](https://public.01-edu.org/subjects/good-practices/)
###### Can you confirm that the project runs and displays a unix interpreter?
###### Can you confirm that the project runs and displays a unix shell?
##### Open a terminal and run the project.
@ -32,7 +32,7 @@
###### 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 child folders using the command "mkdir". Then enter the parent folder and do "pwd".
###### Can you confirm that the interpreter displayed the current path?
@ -58,7 +58,7 @@
##### Create a document inside the `new_folder1` called `new_doc.txt` with some random text inside. Try to run the command `"cp new_doc.txt ../folder2"` to copy the document to the folder `new_folder2`.
###### Can you confirm that the document `new_doc.txt` is inside the `new_folder2`?
###### Can you confirm that the document `new_doc.txt` is inside the `new_folder2`?
##### Try to run the command `"cat new_folder1/new_doc"`. Do the same in your computer terminal.
You must follow the same [principles](https://public.01-edu.org/subjects/0-shell/) as the first subject.
In `scripting` you must find a way to make your `0-shell` run `bash` scripts.
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.
Most users that think of `bash` think of it as a prompt and a command line. That is `bash` in interactive mode. BASH can also run in non-interactive mode, as when executing scripts. We can use scripts to automate certain logic. Scripts are basically lists of commands (just like the ones you can type on the command line), but stored in a file. When a script is executed, all these commands are (generally) executed sequentially, one after another.
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.sh`. 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 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.
Your program must be able not just to run `.sh` files but 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...:
```
for ((i = 0 ; i <100;i++));do
@ -20,26 +20,17 @@ for ((i = 0 ; i < 100 ; i++)); do
###### Was the project written in a compiled programming language?
###### Was the student script created?
###### Was the student shell script created?
#### Functional
##### Try to run the command `"bash create-dir.sh"` in your computer terminal and create the directory "Example".
##### Try to run the student script in your computer terminal and create the directory "Example".
```
Enter directory name
@ -16,7 +16,7 @@ Directory created
###### Can you confirm that the script is valid and the directory "Example" was created like the example above?
##### Try to run the command `"bash create-dir.sh"` 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".
```
Enter directory name
@ -26,7 +26,7 @@ Directory created
###### Can you confirm that the script is valid and the directory "Example1" was created like the example above?
##### Try to run the command `"bash create-dir.sh"` 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".
```
Enter directory name
@ -34,7 +34,7 @@ Example1
Directory exist
```
###### Can you confirm that the script is valid and the directory "Example1" was not created because it 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 the example above?
##### Try to run the command `"NAME="Alex""` followed by the command `"echo "Hello $NAME!""` in the `0-shell` interpreter.