answersLogoWhite

0


Best Answer

perfect code:

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 Name: "

read name

echo "Subject 1: "

read sub1

echo "Subject 2: "

read sub2

echo "Subject 3: "

read sub3

avg=$((($sub1+$sub2+$sub3)/3))

echo "Average : $avg"

record=$rno":"$name":"$sub1":"$sub2":"$sub3":"$avg

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

name=`cut -d ";" -f2 "temp1.txt"`

sub1=`cut -d ";" -f3 "temp1.txt"`

sub2=`cut -d ";" -f4 "temp1.txt"`

sub3=`cut -d ";" -f5 "temp1.txt"`

echo "Enter the value you want to modify"

MENU=" Values

1)Name

2)Subject 1 marks

3)Subject 2 marks

4)Subject 3 marks

"

echo "$MENU"

echo "Enter your choice"

read n1

case $n1 in

1)

echo "Enter the new name"

read name

;;

2)

echo "Enter the new marks for subject 1"

read sub1

;;

3)

echo "Enter the new marks for subject 2"

read sub2

;;

4)

echo "Enter the new marks for subject 3"

read sub3

;;

*)

echo "Enter a vaid choice"

;;

esac

avg=$((($sub1+$sub2+$sub3)/3))

record=$rno";"$name";"$sub1";"$sub2";"$sub3";"$avg

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

#written by:Fabianski Benjamin

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a shell script for student database?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a shell script to show that user is logged in or not?

You don't need a shell script for that; use either 'whoami' or 'id'


How do you write a shell script which counts the last 10 lines present in a given file?

You don't need a shell script to do this - just use the 'tail' command.


When might it be necessary or advisable to write a shell script instead of a shell function?

A shell function will do nothing unless it is explicitly called by other code, typically in a shell script. A shell script is a runnable, executable process, which can call other shell scripts and/or functions. The question might be worded backwards - it is necessary to write shell functions for shell scripts when certain logical functionality is required to be performed multiple times. Consider a shell function equivalent to a program subroutine - they operate the same way.


How do you add two matrices using Linux shell script?

write ashell script to add awo matrix using array.


How do you write a shell script to enlist the processes being run?

#!/bin/sh PS -a


How do you write a statement in DOS using shell script to display a word?

We can not perform Shell Scripting in DOS, we can do Batch programing in DOS..


Is there a way to populate a database with another website's products without having to copy and paste the name of each product into the database?

If you have access to the other website's database you can just make a query there and write a script that then updates your own database with the received values.If you don't, writing a script would most likely be more work than doing it by yourself. You could maybe save some time by getting a list of the product names and then write a script that seperates the names and then writes the values into your database.


How do you write a script which lists the 10 Shell System variables?

You don't need a shell script to do that. Since you don't say what 10 shell variables you want, you can list them all by using the 'set' command to list all known in-use shell variables in the current session.


Write a shell script that counts a number of unique word contained in the alphabetical order line by line?

use python, shell is stupid


Write a shell script to count the number of times is appears in a given text file?

You don't need a shell script to do this; use the 'grep' command with the '-c' option to count the number of occurrences of some pattern.


Write a shell script rename all files whose names end with .c as .old?

for i in *.cdomv $i $i.olddone


Write a program in shell script to display odd number from 0 to 100?

seq 1 2 99