Professional Documents
Culture Documents
Os Lab
Os Lab
S.No. TITLE
01 Program for adding two numbers
02 To check the number is even or not.
12 Write a program in UNIX Shell Programming to display number 1 to 10 using Until Loop.
16 Write a Shell program to find the sum of square of individual digits of a number.
17 Write a Shell program to find the smallest number from a set of numbers.
PROGRAM - 1
Objective: Program for adding two numbers.
Code:
read x
read y
Z=`expr $x + $y`
echo “ result =” $z
OUTPUT :-
PROGRAM – 2
Objective: To cheek the number is even or not.
CODE:
read n
r=`expr $n % 2`
if test $r -eq 0
then
else
fi
OUTPUT :-
PROGRAM – 3
Objective: Program to cheek the largest of three numbers.
CODE:
read x
read y
read Z
if [ $x -gt $y -a $x - gt $z ]
then
elif [ $y -gt $x -a $y gt $z ]
then
else
fi
OUTPUT :-
PROGRAM – 4
Objective: To check all even number in between one to fifty (1 - 50)
CODE:
I=1
rem=0
While test $i - le 50
Do
rem=`expr $i % 2`
then
echo $i
fi
i= `expr $i + 1`
done
OUTPUT :-
PROGRAM-5
Objective: Program to display table.
CODE:
read n
clear
i=1
while test $i le 10
i=`expr $i + 1`
done
OUTPUT :-
PROGRAM-6
Objective: Enter the marks of three subject using keyboard, find the percentage & then declare the division.
CODE:
read Phy
read Chem
read Math
then
echo “ Distinction”
then
then
then
else
fi
OUTPUT :-
PROGRAM – 7
Objective : Display a number in reverse order.
CODE :
read n
while [ $n -ne 0 ]
do
r=`expr $n % 10`
echo $r
n=`expr $n / 10`
done
OUTPUT :-
PROGRAM – 8
Objective : Display the list.
CODE :
for i in 11 22 33 44 55
do
echo “$i”
done
OUTPUT :-
PROGRAM – 9
Objective : Display the content of the file.
CODE :
do
echo “ $i ”
done
OUTPUT :-
PROGRAM – 10
Objective : Display the sequence one to fifty.(1 – 50)
CODE :
for i in { 1….50 }
do
echo “ $i ”
done
PROGRAM – 11
Objective : Display fibonacci series.
CODE :
echo “Enter number upto which you want to print Fibonacci series : ”
read n
x=0
y=1
c=1
echo $x
echo $y
do
z=`expr $x + $y`
echo $z
x=$y
y=$z
c=`expr $c + 1`
done
OUTPUT :-
PROGRAM – 12
Objective : Write a program in UNIX Shell Programming to display number 1 to 10 using Until Loop.
CODE :
x=1
do
echo $x
x=`expr $x +1`
done
OUTPUT :-
PROGRAM – 13
Objective : By using Nesting Loop, display the pattern ;
*
* *
* * *
* * * *
* * * * *
CODE :
OUTPUT :-
PROGRAM – 14
Objective : Write a program to check a number whether it is an Armstrong number or not.
CODE :
read n
temp=$n
s=0
while [ $n -ne 0 ]
do
r=`expr $n %10`
s=`expr $s + $r \* $r \* $r`
n=`expr $n / 10`
done
then
else
fi
OUTPUT :-
PROGRAM – 15
Objective : To check whether the number is Palindrome or not.
CODE:
read m
num=0
temp=$n
while [ $n -gt 0 ]
do
k=`expr $n % 10`
n=`expr $n / 10`
done
then
else
fi
OUTPUT :-
PROGRAM – 16
Objective: Write a Shell program to find the sum of square of individual digits of a number.
CODE:
read n
t=$n
s=0
while [ $n -gt 0 ]
do
r=`expr $n % 10`
s=`expr $s + $r \* $r`
n=`expr $n / 10`
done
OUTPUT :
PROGRAM – 17
Objective: Write a Shell program to find the smallest number from a set of numbers.
CODE:
read a
read b
echo “Enter c”
read c
if [ $a -le $b -a $a -le $c ]
then
echo “ a is smallest”
then
echo “b is smallest”
else
echo “c is smallest”
fi
OUTPUT :-
PROGRAM – 18
Objective : Write a Shell program to find the smallest digit from a number.
CODE:
read n
s=9
while [ $n -gt 0 ]
do
r=`expr $n % 10`
if [ $r -lt $s ]
then
s=$r
fi
n=`expr $n / 10`
done
OUTPUT :-
PROGRAM – 19
Code :
echo "Enter Your Name"
read name
echo "Welcome $name to LinuxHint"
Output :
PROGRAM – 20
Code :
echo "Enter username"
read username
echo "Enter password"
read password
Output :
PROGRAM – 21
Code :
echo "Enter any number"
read n
if [[ ( $n -eq 15 || $n -eq 45 ) ]]
then
echo "You won the game"
else
echo "You lost the game"
fi
Output :
PROGRAM – 22
Code :
echo "Enter your lucky number"
read n
case $n in
101)
echo echo "You got 1st prize" ;;
510)
echo "You got 2nd prize" ;;
999)
echo "You got 3rd prize" ;;
*)
echo "Sorry, try for the next time" ;;
esac
Output :
PROGRAM – 23
Code :
string1="Linux"
string2="Hint"
echo "$string1$string2"
string3=$string1+$string2
string3+=" is a good tutorial blog site"
echo $string3
Output :
PROGRAM – 24
Code :
function greeting() {
str="Hello, $name"
echo $str
val=$(greeting)
echo "Return value of the function is $val"
Output :
PROGRAM – 25
Code :
Output :
PROGRAM – 26
Code :
echo "Enter filename to remove"
read fn
rm -i $fn
Output :
PROGRAM – 27
Code :
echo "Before appending the file"
cat book.txt
Output :
PROGRAM – 28
Code :
echo "Enter a Number"
read n
i=`expr $n - 1`
p=1
while [ $i -ge 1 ]
do
n=`expr $n \* $i`
i=`expr $i - 1`
done
echo "The Factorial of the given Number is $n"
Output :
Code :
echo "Enter Two Numbers"
read a b
temp=$a
a=$b
b=$temp
echo "after swapping"
echo $a $b
Output :
Objective : Writ a Shell program to count the no. of characters in a given string.
CODE :
clear
echo "Enter the string"
read str
len=`expr $str | wc -c`
len=`expr $len - 1`
echo "length of the ‘$str’ is $len"
Output :