Professional Documents
Culture Documents
Experiment2 PDF
Experiment2 PDF
Aim:
The aim of this laboratory is to introduce the shell script that offers the student
with an interface to include a sequence of commands need to employ
frequently for saving me.
Lab Exercise(s):
1. Write a shell script to produce a mul plica on table.
echo “Enter the number”
read n
i=1
while [ $i -le 10 ]
do
let “x=$n * $i”
i=`expr $i +1`
echo $x
done
2. Write a shell script program to implement a small calculator.
echo “Enter 2 numbers”
read a
read b
echo “Enter your Choice”
echo “1. Add”
echo “2. Sub”
echo “3. Mul ply”
echo “4. Division”
read ch
case “$ch” in
“1”) echo “ `expr $a + $b` “
;;
“2”) echo “ `expr $a - $b` “
;;
“3”) echo “ `expr $a * $b` ”
;;
“4”) echo “ `expr $a / $b` “
;;
*) echo “wrong choice entered”
;;
esac
3. Write a shell script to display prime numbers up to the given limit.
read n
i=2
while(($i < $n))
do
ans =$((n%i))
if [ $ans -eq 0 ]
then
echo “$n is not prime number”
exit 0
fi
done
echo “ $n is a prime number”