Reference no: EM134425
Phase 1
The premise of Project 2 is to create your own shell. Your shell will be launchable from a terminal window and act similar to the existing shell.
Groups: You can work in groups of 1-3 people. When you turn in the project, make sure every file has the names of everyone from the group. If you email me the project, just email me the source files. I will assign grades based on the member names in the source files! If you want to author each function or section of code via comments to take credit for parts of the program that is fine, but everyone in the group will receive the same grade regardless of the division of labor.
The next two projects will be group projects based off of this project so choose your groups wisely. You will be allowed to change groups between projects. If a grad student groups up with undergrads, the project must include Part 6
Part 1:
The prompt
Your shell will need to provide a prompt to the user.
![46_create your own shell.png](https://www.expertsmind.com/CMSImages/46_create%20your%20own%20shell.png)
an example of the windows command line prompt
The prompt will be able to display information to the user to provide them with information about their environment. By default, your prompt should be include the Current Working Directory.You will need to implement a setprompt command in your shell. An example of the setprompt would be:
setprompt %PWD%$
which then would display a prompt like:
/home/brian/$
Use %PWD% as a substitute for where to insert the current working directory for the prompt string. After every command is run, you need to display the prompt string to ask for the next user input.
Part 2:
Implement the "cd" command. the CD command changes the current working directory of the process. Your shell should be able to handle commands like the following:
/$ cd bin
changes from / to /bin/, since we are currently in /
cd /
changes from CWD to /
/$ cd home/bin
changes from / to /home/bin, since we are currently in /
/home/brian/$ cd ..
changes from /home/brian/ to /home/ (goes up one directory)
/home/brian/$ cd ../..
changes from /home/brian/ to / (goes up 2 directories)
/home/brian/$ cd /tmp
changes from /home/brian/ to /tmp/ since /tmp was specified from the root dir
Part 3:
dir command.
Your program will implement a dir command. This command acts much like the ls command within the normal linux terminal. You cannot simply exec the ls command. you will need to implement it via the opendir and readdir commands.
for example exeucting
/home/$ dir
would output a list of files each on its own line:
.
..
brian
tamarra
matt
justin
Assuming the home directory contained entries for each of those people.
As arguments to dir you will need to handle:
-s=<option>
options: name, adate, type
The sort option will sort the results by the specified parameter before printing them out to the screen. (adate is date of last access, type is file type, name is filename)
-r
recursive. dir will output the files within the current working directory and every sub directory within, recursively entering deeper and deeper into the directory structure.
Example output:
/home/$ dir -r
.
..
brian
tamarra
matt
justin
/home/brian/
.
..
workspace
documents
assignments
tmp
/home/brian/workspace/
.
..
project1
project2
project3
/home/brian/documents/
.
..
lab1
lab2
lab3
midterm
/home/tamarra/
.
..
projects
documents
finally
-i
displays a directory listing similar to ls -l, which outputs the files inside a directory with all their attributes. Attributes must include at least:
permissions, size, owner, group, access date, modified date, filename
flags can be combined! so you could have something like
dir -s=name -r -i
which will sort files in a directory by name, and then recursively display detailed information for all files in the directory and all sub directories. Order of options specified in the argument list can vary. You could have -s -i -r or -i -r -s or -r -i -s etc.
Part 4
Redirection and piping. Your shell will need to handle the redirect characters and the pipe character. for example:
dir -s=name > dirout.txt
would perform the dir command, with the sort option and write the results to the file dirout.txt in the current working directory.
Part 5
Fork and Exec for other functionality.
Since I cannot have you completely rewrite all the tools available through the linux terminal, your shell will need to be able to fork and exec any command it doesn't recognize. You should use the which command to determine if the entered programs actually exist before attempting to fork and exec. Display an error if the commands do not exist.
Your fork and exec must support redirection and piping as well. I should be able to execute:
dir -i -r | grep cpp > allsourcefiles
Part 6
you will need to implement a cat function similar to the cat in the existing linux terminal.
cat file1 - file2
Output file1's contents, then standard input, then file2's contents to standard output.
cat
Copy standard input to standard output.
For simplicity sake, end the input from standard input when 2 newline characters are read back to back.
Conclusion and other thoughts
It would be nice to include an exit command to terminate your shell. so if the user types in exit, quit your shell.
Also to be user friendly, you could store the users prompt value, so they wouldn't have to reset it every time they run the program.