0% found this document useful (0 votes)
14 views15 pages

III - Cs - Linux - Record

The document contains a series of shell scripts that perform various tasks including checking if a number is prime, finding the largest of two numbers, determining if a number is odd or even, generating a Fibonacci series, calculating electricity bills, managing student details, preparing payroll, counting vowels in a string, sorting numbers, and managing a biodata database. Each script provides user prompts for input and outputs results based on the calculations or operations performed. The examples include user interactions and expected outputs for each script.

Uploaded by

cammusowmiya13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views15 pages

III - Cs - Linux - Record

The document contains a series of shell scripts that perform various tasks including checking if a number is prime, finding the largest of two numbers, determining if a number is odd or even, generating a Fibonacci series, calculating electricity bills, managing student details, preparing payroll, counting vowels in a string, sorting numbers, and managing a biodata database. Each script provides user prompts for input and outputs results based on the calculations or operations performed. The examples include user interactions and expected outputs for each script.

Uploaded by

cammusowmiya13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

1.

Given number is prime or not

echo "Enter the number"


read a
i=2
z=0
while [ $i -lt $a ]
do
s=`expr $a % $i`
if [ $s -eq $z ]
then
echo "Not Prime"
exit
else
i=`expr $i + 1`
fi
done
echo "Prime number"

Output:
Enter the number
7
Prime number
[redhat35@localhost Rhel5]$ sh prime.sh
Enter the number
4
Not Prime
2 . Find the biggest of given two numbers

echo "Enter the first number”


read a
echo "Enter the second number "
read b
if [ $a –gt $b ]
then
echo “ $a is greater than $b”
else
echo “$b is greater than $a”
fi

Output:

Enter the first number : 20


Enter the second number : 30
30 is greater than 20
3. Odd or Even

echo "ENTER THE NUMBER"


read n
rem=$(( $n % 2 ))
if [ $rem -eq 0 ]
then
echo "$n is even"
else
echo "$n is odd"
fi

OUTPUT::
ENTER THE NUMBER
5
5 is odd
4. Fibonacci Series

echo "ENTER THE NO"


read n
a=0
b=1
echo "The Fibonacci Series Is"
for (( i=0; i<n; i++ ))
do
echo -n "$a"
fn=$((a+b))
a=$b
b=$fn
done

OUTPUT:
ENTER THE NO
5
The Fibonacci Series Is
0
1
2
3
5. Electric Bill For Domestic Consumers.

clear
echo
echo '\tCalculate Electricity Charge'
echo
echo Enter the Name
read name
echo Enter the Meter number
read mno
echo Enter the current month rea ding
read cmr
echo Enter the last month reading
read lmr
unit=$(expr $cmr - $lmr)
if [ $unit -eq 0 ]
then
charge=40
elif [ $unit -gt 0 ] && [ $unit -le 100 ]
then
charge=$(expr $unit \* 1)
elif [ $unit -gt 100 ] && [ $unit -le 300 ]
then
charge=$(expr 100 \* 1 + $unit - 100)
elif [ $unit -gt 300 ] && [ $unit -le 500 ]
then
charge=$(expr $unit \* 1 + 200 \* 2 + $unit - 300)
elif [ $unit -gt 500 ]
then
charge=$(expr 1400 + $unit - 400)
fi
echo
echo '\tElectricity Billing'
echo
echo "Name : $name"
echo "Meter Number : $mno"
echo "Current Month reading : $cmr"
echo "Last Month reading : $lmr"
echo "Unit : $unit"
echo "Charge : $charge"
echo
output:

-
Calculate Electricity Charge
-
Enter the Name
SATHEESH
Enter the Meter number
E1234
Enter the current month reading
456
Enter the last month reading
123
-
Electricity Billing
-
Name : SATHEESH
Meter Number : E1234
Current Month reading : 456
Last Month reading : 123
Unit : 333
Charge : 766
6. Students Details

clear
echo
echo '\tStudent Mark List'
echo
echo Enter the Student name
read name
echo Enter the Register number
read rno
echo Enter the Mark1
read m1
echo Enter the Mark2
read m2
echo Enter the Mark3
read m3
echo Enter the Mark4
read m4
echo Enter the Mark5
read m5
tot=$(expr $m1 + $m2 + $m3 + $m4 + $m5)
avg=$(expr $tot / 5)
echo
echo '\tStudent Mark List'
echo
echo "Student Name : $name"
echo "Register Number : $rno"
echo "Mark1 : $m1"
echo "Mark2 : $m2"
echo "Mark3 : $m3"
echo "Mark4 : $m4"
echo "Mark5 : $m5"
echo "Total : $tot"
echo "Average : $avg"
if [ $m1 –ge 50 ] && [ $m2 -ge 50 ] && [ $m3 -ge 50 ] && [ $m4 –ge 50 ] && [ $m5 -ge 50 ]
then
echo "Result : Pass"
if [ $avg -ge 90 ]
then
echo "Grade : S"
elif [ $avg -ge 80 ]
then
echo "Grade : A"
elif [ $avg -ge 70 ]
then
echo "Grade : B"
elif [ $avg -ge 60 ]
then
echo "Grade : C"
elif [ $avg -ge 50 ]
then
echo "Grade : D"
elif [ $avg -ge 35 ]
then
echo "Grade : E"
fi
else
echo "Result : Fail"
fi
echo
OUTPUT

Student Mark List

Enter the Student name


SATHEESH
Enter the Register number
182123
Enter the Mark1
89
Enter the Mark2
76
Enter the Mark3
98
Enter the Mark4
89
Enter the Mark5
96

Student Mark List

Student Name : SATHEESH


Register Number : 182123
Mark1 : 89
Mark2 : 76
Mark3 : 98
Mark4 : 89
Mark5 : 96
Total : 448
Average : 89
Result : Pass
Grade :A
7. prepare a Payroll

echo -e "Enter ur basic salary \c"


read sal
if [ $sal -ge 1000 ]
then
da=`expr $sal \* 40 / 100`
ha=`expr $sal \* 20 / 100`
pf=`expr $sal \* 12 / 100`
Nsal=`expr $sal + $da + $ha - $pf`
echo "ur Basic Salary $sal "
echo "ur Dearness Allowance $da "
echo "Ur House rent $ha "
echo " "
echo "Ur Gross pay salary is Rs. $Nsal "else
echo "Pls enter basic salary greater than 1000 "
fi

output:

Enter your basic salary 60000


Basic Salaray 60000
Dearness allowance 24000
pf 7200
House rent 12000

gross pay salary is Rs.96000


8. Vowels

clear
echo
read str
len=$(expr length $str)
count=0
while [ $len -gt 0 ]
do
ch=$(echo $str | cut -c $len)
case $ch in
[aeiouAEIOU] )
count=$(($count + 1))
echo “The vowels are $ch”
;;
esac
len=$(( $len - 1 ))
done
echo “Total No of vowels are $count”

Output
Enter the word
English
vowels are
i
e
Total no of vowels:2
9. Ascending order descending order

echo enter the no of element


read n1
for (( i=0; i<$n1; i++ ))
do
echo enter `expr $i + 1` the element.
read a[$i]
done
for (( i=0; i<$n1; i++ ))
do
for (( j=`expr $i + 1`; j<$n1; j++ ))
do
if [ ${a[$i]} -gt ${a[$j]} ]
then
x=${a[$i]}
a[$i]=${a[$j]}
a[$j]=$x
fi
done
done
echo 1.Ascending 2.Descending
echo enter your choice...
read c
if [ $c = 1 ]
then
echo the ascending order is....
for (( i=0; i<$n1; i++ ))
do
echo ${a[$i]}
done
elif [ $c = 2 ]
then
echo the descending order is...
for (( i=$n1; i>0; i-- ))
do
echo ${a[`expr $i - 1`]}
done
else
echo wrong choice......
fi
OUTPUT

enter the no of element


5
enter 1 the element.
1
enter 2 the element.
6
enter 3 the element.
2
enter 4 the element.
9
enter 5 the element.
4
1. Ascending 2.Descending
enter your choice...
1
the ascending order is....
1
2
4
6
9
10. Biodata

clear
i="y"
echo "Enter name of database "
read db
while [ $i = "y" ]
do
clear
echo "1.View the Data Base "
echo "2.View Specific Records "
echo "3.Add Records "
echo "4.Delete Records "
echo "5.Exit "
echo "Enter your choice "
read ch
case $ch in
1)cat $db;;
2)echo "Enter id "
read id
grep -i "$id" $db;;
3)echo “enter name”
read name
echo "Enter qualification"
read tid
echo "Enter address:"
read tnm
echo "Enter fathername "
read des
echo "Enter Hobbies”
read hobbies
echo "$tid $tnm $des $college">>$db;;
4)echo "Enter Id"
read id
# set -a
# sed '/$id/d' $db>dbs1
grep -v "$id" $db >dbs1
echo "Record is deleted"
cat dbs1;;
5)exit;;
*)echo "Invalid choice ";;
esac
echo "Do u want to continue ?"
read i
if [ $i != "y" ]
then
exit
fi
done
Output:
Enter name of the database: Anitha
1.view the database
2. iew specific Records
3.Add records
4.Delete Records
5.Exit
Enter your choice:3
Enter the id :4
Enter the name: Anitha
Enter qualification : B.Sc computer science
Enter address : Madurai
Enter father name : Jayakumar
Enter hobbies : Listening songs
Do you want to continue
y
Enter your choice :2
enter id :4
Name :anitha
qualification:B.sc computer science
address :Madurai
fathername :jayakumar
hobbies :listening songs
Do you want to continue Y
Enter your choice :4
enter id :4
Deleted successfully
Do you want to continue
y
Enter your choice :1
anu anitha bovunya harini reethu
Do you want to continue
y
Enter your choice :5
Exit

You might also like