Practical File For Operating System
Practical File For Operating System
opasdfghjklzxcvbnmqwertyuiopasdfgh
DEEN DAYAL UPADHYAYA COLLEGE
jklzxcvbnmqwertyuiopasdfghjklzxcvb
BSC(MATHEMATICAL SCIENCE)
nmqwertyuiopasdfghjklzxcvbnmqwer
tyuiopasdfghjklzxcvbnmqwertyuiopas
dfghjklzxcvbnmqwertyuiopasdfghjklzx
OPERATING SYSTEM
cvbnmqwertyuiopasdfghjklzxcvbnmq
LAB PRACTICALS
BY-
wertyuiopasdfghjklzxcvbnmqwertyuio
Himanshu Rawat(18MTS5919)
pasdfghjklzxcvbnmqwertyuiopasdfghj
klzxcvbnmqwertyuiopasdfghjklzxcvbn
mqwertyuiopasdfghjklzxcvbnmqwerty
uiopasdfghjklzxcvbnmqwertyuiopasdf
ghjklzxcvbnmqwertyuiopasdfghjklzxc
vbnmqwertyuiopasdfghjklzxcvbnmrty
uiopasdfghjklzxcvbnmqwertyuiopasdf
ghjklzxcvbnmqwertyuiopasdfghjklzxc
1) write a shell script to display the multiplication
table any number
Ans )
echo -n "enter your number" ;read n
count=1
Output:-
do
((rem=$n%10))
((sum=sum+rem))
((n=n/10))
done
echo “The sum of digits of $num is $sum”
Output:-
Output:-
5) write a shell script to find the power of a given
number
Ans )
echo -n "Input no" ; read no
echo -n "Input power" ; read power
ans=1
for ((counter=1;counter<=power;counter++))
do
((ans=no*ans))
done
echo "Your ans is $ans"
Output:-
Output:-
7) write a shell script to perform the task of basic
calculator.
Ans )
echo "enter any two number:"
read a
read b
echo "enter choice :"
echo "1. Addition "
echo "2. Subtraction "
echo "3. Multiplication "
echo "4. Division "
read ch
case $ch in
1) res=`echo $a +$b | bc`;;
2) res=`echo $a - $b | bc`;;
3) res=`echo $a \* $b | bc`;;
4) res=`echo "scale=2; $a / $b " | bc`;;
esac
echo "Result : $res"
Output:-
Output:-
Output:-
Output:-
rm t1 t2 t3
else
echo "Files with these name do not exist"
fi
cat sm.txt | more | less
Output:-
Output:-
for m in $@
do
m1=`echo $m | tr " [A-Z] " "[ a-z] "`
case $m1 in
jan* ) m1=1 ;;
feb* ) m1=2 ;;
mar* ) m1=3 ;;
apr* ) m1=4 ;;
may* ) m1=5 ;;
jun* ) m1=6 ;;
jul* ) m1=7 ;;
aug* ) m1=8 ;;
sep* ) m1=9 ;;
oct* ) m1=10 ;;
nov* ) m1=11 ;;
dec* ) m1=12 ;;
* ) echo -e "You have Entered Invalid Month\n"
esac
set `date`; y=$6
cal $m1 $y
done
Output:-
17) write a shell script to modify “cal” command to
display calendars of the specified range of months.
Ans )
mon1=`echo $* | tr -s "." | cut -d"." -f1`
mon2=`echo $* | tr -s "." | cut -d"." -f2`
FEB) m2=2;;
MAR) m2=3;;
APR) m2=4;;
MAY) m2=5;;
JUN) m2=6;;
JUL) m2=7;;
AUG) m2=8;;
SEP) m2=9;;
OCT) m2=10;;
NOV) m2=11;;
DEC) m2=12;;
* ) echo -e "wrong month\n"
esac
for((i=m1;i<=m2;i++))
do
cal $i $y
done
else
echo "invalid range of months"
fi
Output:-
m=$a
if [ $b -lt $m ]
then
m=$b
fi
while [ $m -ne 0 ]
do
((x=$a%$m))
((y=$b%$m))
if [ $x -eq 0 -a $y -eq 0 ]
then
echo "GCD of $a and $b is $m"
break
fi
((m=$m-1))
done
Output:-