UNIX ASSIGNMENT (1) 20 Pages
UNIX ASSIGNMENT (1) 20 Pages
ASSIGNMENT
#2. Write a shell program to Print Student Name and Marks of three students
that is enter by users.
#3. Write a shell script program to perform all Arithmetic operations on two
integers which is input by users.
#5. Write the shell program to Enter the Principal , Rate and Time from the
user and find the simple interest.
clear
echo "Enter P,N and R"
read p
read n
read r
si=`expr \( $p \* $n \* $r \) / 100`
echo "Simple Interest is " $si
#6. Write a shell script program to find area of circle, Rectangle and Square.
#7. Write a shell script program to print our Address ‘n’ times by users.
#8. Write a shell script program to find whether the given number is even or
odd input by users.
#9. Write a shell script program to find whether number is positive , negative
or zero.
clear
echo "Enter n"
read n
if [ $n -gt 0 ]
then
echo "n is positive"
else
if [ $n -eq 0 ]
then
echo "n is zero"
else
echo "n is negative"
fi
fi
#10. Write a shell script program to enter the three numbers from user and
find the Greatest of three numbers.
clear
echo "Enter any 3 numbers"
read x
read y
5 NAVIN KUMAR MISHRA
read z
if [ $x -gt $y -a $x -gt $z ]
then
echo $x " is Great"
else
if [ $y -gt $z ]
then
echo $y " is Great"
else
echo $z " is Great"
fi
fi
#11. Write a shell script program to enter the year and find whether year is
leap year or not.
#12. Write a shell script program to enter a number and check whether
number is divisible by 11 or not.
#14. Write a shell script program to print perfect numbers from 1 to 100
clear
echo "Enter a Number"
read n
s=0
while [ $n -gt 0 ]
do
r=`expr $n % 10`
s=`expr $s \* 10 + $r`
n=`expr $n / 10`
done
echo "Reverse of it is" $s
#17. Write a shell script program to print multiplication table using FOR loop
of any number.
echo "Enter the number"
read n
echo "Multiplication Table"
for ((i=1;i<10;i++))
8 NAVIN KUMAR MISHRA
do
echo $n " * " $i " = " `expr $n \* $i`
done
Output :
Enter the number
34
Multiplication Table
34 * 1 = 34
34 * 2 = 68
34 * 3 = 102
34 * 4 = 136
34 * 5 = 170
34 * 6 = 204
34 * 7 = 238
34 * 8 = 272
34 * 9 = 306
34 * 10 = 340
#18. Write a shell script program to print prime numbers between 1 to 20.
#19. Write a shell script program to enter a number from user and find
whether number is prime or not
#20. Write a shell script program to enter a number and check whether
number is Armstrong or not
#21. Write a shell script program to print Armstrong numbers from 1 to 1000
clear
echo "Enter n"
read n
f=1
while [ $n -gt 0 ]
do
f=`expr $f \* $n`
n=`expr $n - 1`
done
echo "Factorial is " $f
#23. Write a shell script program to enter the limit of number and print the
Fibonacci series.
declare -a num[]
echo "Enter length of list"
read n
i=0
echo "Enter list of Numbers"
for ((i=0;i
do
read num[$i]
done
echo "Sum till a negative no : "
s=0
for ((i=0;i
do
if [ num[$i] -gt 0 ]
then
s=`expr $s + $num[$i]`
else
break
fi
done
echo $s
13 NAVIN KUMAR MISHRA
#26. Write a shell script program to enter the digit from a number print the
corresponding day Using else if ladder.
#28. Write a shell script program to print the corresponding day Using elif
structure
echo “Enter day no.”
read d
if [ $d –eq 1 ]
then
echo “Sunday”
elif [ $d –eq 2 ]
then
echo “Monday”
elif [ $d –eq 3 ]
then
echo “Tuesday”
elif [ $d –eq 4 ]
then
echo “Wednesday”
elif [ $d –eq 5 ]
then
echo “Thursday”
elif [ $d –eq 6 ]
then
echo “Friday”
elif [ $d –eq 7 ]
then
echo “Saturday”
else
echo “Enter the day no. between 1-7”
fi
15 NAVIN KUMAR MISHRA
#29. Write a shell script program to print the corresponding day Using case
control structure.
#30. Write a shell script program to accept a character and check it character
is vowel ,lower alphabet , upper alphabet and digit.
clear
echo “Enter any character”
read d
case $d in
[a,e,i,o,u,A,E,I,O,U])echo “It is a Vowel”
;;
16 NAVIN KUMAR MISHRA
[a-z])echo “It is a Lower case alphabet”
;;
[A-Z)echo “It is a Upper case alphabet”
;;
[0-9])echo “It is a digit”
;;
*)echo “It is a Special Symbol”
esac
ch='y'
while [ $ch = 'y' ]
do
echo "Enter u r choice---"
echo "1)No of Users Logged into System"
echo "2)Print Calendar for current year"
echo "3)Print the date"
echo "4)Exit"
read d
case $d in
1)who | wc -l
;;
2)cal 2011
;;
3)date
;;
*)break
esac
echo "Do u wish to Continue (y/n)"
read ch
done
#32. Write a shell script program to check given file is a directory or not
echo “Enter the filename”
read fn
17 NAVIN KUMAR MISHRA
if [ -f $fn ]
then
echo "It is a file "
else
echo "It is a directory "
fi
#34. Write a shell script program to search an element is present in list or not
declare -a num[]
echo "Enter length of list"
read n
i=0
echo "Enter list of Numbers"
for ((i=0;i
do
read num[$i]
done
echo "Enter element to be searched"
read x
c=0
for ((i=0;i
18 NAVIN KUMAR MISHRA
do
if [ $x -eq $ { num[$i] } ]
then
c=`expr $c + 1`
fi
done
if [ $c -gt 0 ]
then
echo "It is in the List"
else
echo "It is not in the list"
fi
#36. Write a shell script program to o copy the contents of one file to
another.
clear
echo "Enter the source file"
read a
echo "Enter the destination file”
read b
cp $a $b
cat $b