Script
Script
FACTORIAL OF N
OUTPUT:
Enter the number to be factorialed
6
sum =720
2. FIBONACCI SERIES
OUTPUT:
Enter your choice
1
SHOW ME THE DATE
15/04/06
Enter your choice
WHAT IS THE TIME
14/41/06
Enter your choice
8
NOT A GIVEN CHOICE
4. PRIME NUMBER
OUTPUT ;
Enter a number
23
PRIME
Enter a number
12
NOT PRIME
5. PRIME NUMBER BETWEEN RANGE
OUTPUT :
OUTPUT :
n=0
while [ $n –ne 5 ]
do
clear
echo –e “\n MENU\n 1. ADDITTION 2. SUBTRACTION
3. MULTIPLICATION\n 4. DIVISION\n 5. EXIT\n\n
Enter your option: \c”
read n
case $n in
1) echo –e “\n Enter two numbers for addition: \n
NUMBER1: \c”
read n1
echo –e “ NUMBER2: \c”
read n2
echo –e “ The sum is: \c”
echo `expr $n1 + $n2`;;
2) echo –e “\n Enter two numbers for subtraction: \n
NUMBER1: \c”
read n1
echo –e “ NUMBER2 \c”
read n2
echo –e “ The difference is: \c”
echo `expr $n1 - $n2`;;
3) echo –e “\n Enter two numbers for multiplication: \n
NUMBER1 : \c”
read n1
echo –e “ NUMBER2: \c”
read n2
echo –e “ The product is: \c”
echo `expr $n1 \ * $2 `;;
4) echo –e “\n Enter two numbers for division: \n
NUMBER1: \c”
read n1
echo –e “ NUMBER2: \c”
read n2
echo –e “ The quotient is: \c”
echo `expr $n1 / $n2 `;;
5) clear
exit;;
esac
sleep 3
OUTPUT :
MENU
1. ADDITION
2. SUBSTRACTION
3. MULTIPLICATION
4. DIVISION
5. EXIT
MENU
1. ADDITION
2. SUBSTRACTION
3. MULTIPLICATION
4. DIVISION
5. EXIT
program
$cat>pm.sh
clear
echo “Enter the year:”
read year
((a=$year %4))
((b=$year %100))
((c=$year %400))
if [ $a –eq 0 –a $b –ne 0 ]
then
echo “year is not leap year”
elif test $c –eq 0
then
echo “year is leap year”
fi
OUTPUT :
OUTPUT :
$cat>pal.sh
clear
echo “Enter the number:”
raed n
((k=n))
d=0
while [$n –ne 0]
do
((r=n%10))
((r=10*d+r))
((n=(n-r)/10))
done
if $k –eq $d
then
echo “The number is palindrome”
else
echo “The number is not palindrome”
fi
OUTPUT :
11. WRITE A SHELL SCRIPT TO CHECK WHETHER ASUPPLIED NAME IS EXICUTABLE OR NOT
$cat>s3.sh
echo “Enter any file name:”
raed fn
if [ ! –d $fn ]
then
if [ ! –x $fn ]
then
echo “$fn is not an executable file”
else
echo “ $fn is an executable file”
fi
else
echo “ $fn is a directory”
fi
OUTPUT :
OUTPUT :
Enter any string_
Madam
Palindrome
Enter any string_
Vidyasagar
Not palindrome
13. ENTER A NUMBER OF NAME AND SORT THEM THEN DISPLAY ON THE SCREEN
echo
echo “***********************”
echo “Enters the names”
echo “Press ctrl+d to get Result”
cat –u > name
echo
echo “ The sorted form of the Names”
echo
for nvar in name
do
sort $var
done
echo
OUTPUT :
14.G.C.D CALCULATION
OUTPUT :
Enter any two number
15
10
The GCD is 5
read x
a[$i]=$x
i=` exor Si + 1`
done
i=0
while [ $i –lt $n ]
do
j=` expr $i + 1`
while [ $j –lt $n ]
do
if [ ${a[$i]} –gt ${s[$j]} ]
then
temp = ${a[$i]}
a[$i] = ${a[$j]}
a[$j] = temp
fi
j=` expr $j + 1`
done
OUTPUT :
OUTPUT :
OUTPUT :
OUTPUT:
Enter the value of n
5
Enter the value of r
2
****MENU****
1- FOR NCR
2- FOR NPR
****MENU****
1- EOR NCR
2- FOR NPR
power=1
while test $i –le $cnt
do
power=`expr $power \*2`
i=`expr $power \*2`
i=`expr $i = 1
done
dec=`expr $dec = $rem\*$power`
bin=`expr $bin / 10`
cnt=`expr $cnt + 1`
done
echo `The equivalent decimal number of given binary number` $binary` is:`de
OUTPUT:
$cat>pm.sh
clear
echo “Enter the 1st no.:”
read no 1
echo “Enter the 2nd no.:”
readno2
if [$no1 –gt $no2]
then
big=$no1
if [ $no2 –gt $no1]
tehn
big=$no2
fi
echo $big
OUTPUT:
OUTPUT:
(a)
Enter a number for checking even or odd
40
The number 40 you enter is even
(b)
Enter a number for checking even or odd
5
The number 5 you enter is odd
>>Program which calculate sum of the non zero digit of a given number also count the number of non
zero digit:
OUTPUT:
Enter a number
23507
OUTPUT:
$cat>sill.sh
clear
echo “ Enter any file name”
read fn
if [ !-f $fn ]
then
echo “file does not exit”
sleep 5
else
cat $fn
fi
OUTPUT:
$cat>s3.sh
echo “Enter any file name:”
read fn
if [ !-d $fn]
then
if [!-x $fn]
then
echo “$fn is not an executable file”
else
echo “$fn is an executable file”
fi
else
echo “$fn is a directory”
fi
OUTPUT: