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
You don't need a shell script for that; use either 'whoami' or 'id'
You don't need a shell script to do this - just use the 'tail' command.
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.
write ashell script to add awo matrix using array.
#!/bin/sh PS -a
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.
We can not perform Shell Scripting in DOS, we can do Batch programing in DOS..
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.
use python, shell is stupid
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.
seq 1 2 99
for i in *.cdomv $i $i.olddone