UNIX/Linux – operating system
2 of 7 Bonus Assignment
BASH Scripting
Introduction
For this assignment, you need to create and submit a BASH script. I have divided the assignment
into two parts to help you test your script. You will only submit the final application you write.
Note: You must name the script file net211_assn2
Submission
You will submit the BASH script. I will download this file and execute the script on my Linux
system with my own ‘database’ text file. You will receive grades based on how well your script
implements the application requirements. You will also receive a grade for creativity; based on
usability (this includes how well you design your menu etc.)
SUBMIT: net211_assgn2
DUE DATE: March 3, 2016 at 11:59pm
Instructions
Part One:
1. Go to your Documents directory and create a subdirectory called assignment2.
Change in to this new directory and create you script file here.
2. You will use either vi or emacs to write your script, and test it in your terminal.
Overview:
Create a menu for an application that will process class list information.
Your menu will present the user with the following choices:
(P)rint class list
(A)dd new student
(S)earch for a student
(D)elete a student
(Q)uit
3 of 7 Bonus Assignment
It will look something like the menu in the picture below:
Use the read command to read user’s input. Print the user selection on the screen.
Details:
For this part of assignment you need to write a simple BASH script that outputs the above menu
and waits for user input. It reads the character entered by the user and prints out the character,
along with the command it corresponds too. Your script should be case insensitive (i.e. it should
work both if a lowercase letter or an uppercase letter is entered). It should output the character
followed by “Invalid Option” if an incorrect letter is input. The script should then wait for further
input. This should continue in a loop until the user enters “Q” or “q”.
The script will not perform any processing of commands yet (other than quit). We will develop it
further part two to create our Class List application.
Following is an example of what your script should do for this part:
4 of 7 Bonus Assignment
Tips:
– Start your script with a clear command, so that your program starts with a clean screen
every time.
– Use a while or until loop for repeatedly reading user input.
– Use nested ifs or a case statement to print the correct output based on the input.
5 of 7 Bonus Assignment
Part Two:
You will continue to work with the same script file.
Make the following updates to your script:
1. Each of your menu choices will now call a function to perform file processing rather than
simply printing the menu option to the screen:
a. <P>rint class list: Write a function named print_class_list that will check if a
file named classlist.txt exists or not. If the file exists, it will print the file to the
terminal.
b. <A>dd new student: Write a function named add_new_student that will
prompt the user to enter the student number, last name, and first name of a new
student. Append the new student to the end of the file named classlist.txt, then
sort the file by student number (numerical sort). Recall the steps to sort the file
(redirect the output of sort to a new file, and then rename the new file to the name
of the old file).
**MAKE SURE THERE ARE NO DUPLICATE ENTRIES.
STUDENT NUMBERS MUST BE UNIQUE **
NOTE: The format of classlist.txt is as follows: it contains one line for each
student. Each line has three tab separated columns, the first is the student number,
the second is the last name and the third is the first name. You must make sure
that when you add a new student to the file, you use this format.
Illustration 1: Printing from a file
6 of 7 Bonus Assignment
Illustration 2: Appending a new student to a file
c. <S>earch for a student: Write a function named search_for_student that
will prompt the user to enter the student number to search for. Then it will check
if a file named classlist.txt exists or not. If the file exists it will search the file
for the requested student number (use grep). If a match is found print the
requested line(s) to the terminal otherwise inform the user that no such student
number exists in the class list. If the file does not exist, print an appropriate error
message.
Illustration 3: Searching for a student
7 of 7 Bonus Assignment
d. <D>elete a student: Write a function named delete_student that will prompt
the user to enter the student number of the student to delete. Then it will check if a
file named classlist.txt exists or not. If the file exists it will search the file for
the requested student number and delete it (use sed or a combination of grep and
sed). If a match is found simply delete, if no match is found print an error
message. If the file does not exist, print an appropriate error message.
Illustration 4: Deleting a student
Additional Notes:
1. Use comments in your program.
2. Keep it simple!
3. Try to make the interface of your program as user friendly as possible. The screen shots
provided are just here as an example of functionality, and do not necessarily represent
the best layout.
4. I will be using my own classlist.txt to test your program, so make sure you follow
the correct format (tab separated three columns: student number, last name, first name).
TAKE ADVANTAGE OF OUR PROMOTIONAL DISCOUNT DISPLAYED ON THE WEBSITE AND GET A DISCOUNT FOR YOUR PAPER NOW!