Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Bash/Unix script Create 4 Functions (One For Each Menu Item) That Performs The A

ID: 3693514 • Letter: B

Question

Bash/Unix script

Create 4 Functions (One For Each Menu Item) That Performs The Action Of The Selected Option

Add Student

Prompt User For The Following Information

Student ID (Make Sure It Is Not Already Taken)

Student First Name

Student Last Name

Student Grade Level

Student Classroom

Modify Student

Prompt User For Student ID

If the ID Does Not Exist, Alert The User And Return To Main Menu

If The ID Exists, Prompt User For New Information, display original info as well

Remove Student

Prompt User For Student ID

If the ID Does Not Exist, Alert The User And Return To Main Menu

List All Students

Display Current Student Information (Information Stored In Temp File)

Save And Quit

Take The Contents Of The Temp File And Save Them To The User Inputted File

Quit Without Saving

Delete The Temp File. Do Not Modify The User Inputted File

Quit The Script

Your script should continue to run until the user selects to quit the script. So after each action is performed, return the user to the main menu

Explanation / Answer

in linux system (for ex-ubuntu) -> save using studentDb.sh

run using

sh studentDb.sh

OR

bash studentDb.sh

create ()
{
echo "Enter the filename which you want to create"
read db
touch $db
echo "File created"
}

insert()
{
if [ -z $db ];then
echo "Database doesnt exist. Create a new database."
else
echo "Enter the number of records to be added."
read no
while [ $no -gt 0 ]
do
echo "Enter roll no: "
read rno
srno=`grep "^$rno" "$db"`
if [ -z $srno ]
then
echo "Enter fName: "
read fname
echo "lname: "
read lname
echo "Glevel: "
read Glevel
echo "class room: "
read classroom
record=$rno":"$fname":"$lname":"$Glevel":"$classroom
echo $record >> "$db"
no=$(($no-1))
else
echo "Record already exists."

fi
done
fi
}

search()
{
echo " Enter roll no: "
read rno

record=`grep "^$rno" "$db"`
if [ $? -ne 0 ]; then
echo "Record doesnt exist. "
else
echo "Record found"
echo $record
fi
}

modify()
{
echo " Enter roll no to modify: "
read rno
grep "^$rno" $db > temp1.txt
grep -v "^$rno" $db > temp2.txt
mv temp2.txt $db
if [ $? -ne 0 ]; then
echo "Record doesnt exist. "
else

fname=`cut -d ";" -f2 "temp1.txt"`
lname=`cut -d ";" -f3 "temp1.txt"`
Glevel=`cut -d ";" -f4 "temp1.txt"`
classroom=`cut -d ";" -f5 "temp1.txt"`
echo "Enter the value you want to modify"
MENU=" Values
1)Fame
2)Lname
3)Glevel
4)classRoom
"
echo "$MENU"
echo "Enter your choice"
read n1
case $n1 in

1)
echo "Enter the first name"
read fname
;;
2)
echo "Enter the last name"
read lname
;;
3)
echo "Enter the G level"
read Glevel
;;
4)
echo "Enter class room"
read classroom
;;
*)
echo "Enter a valid choice"
;;
esac
record=$rno";"$name";"$sub1";"$sub2";"$sub3
echo $record >> "$db"
fi
}

delete()
{
echo " Enter roll no: "
read rno

record=`grep "^$rno" "$db"`
if [ $? -ne 0 ]; then
echo "Record doesnt exist. "
else
echo "Record found"
echo $record

record=`grep -v "^$rno" "$db" > tmp.txt`
mv tmp.txt $db
echo "Record deleted."
fi
}

display()
{
echo " Complete database..."
cat $db
}


MENU1="***********Menu***********
1)Create
2)Insert
3)Search
4)Modify
5)Delete
6)Display
7)Exit
"
while true
do
echo $MENU1
echo "Enter the choice: "
read n
case $n in

1) create
;;
2)insert
;;
3) search
;;
4) modify
;;
5) delete
;;
6) display
;;
7) exit
;;
esac
done

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote