Professional Documents
Culture Documents
_______________
----------------------------
sum of 2 numbers
_________________
-------------------------------
odd or even
_____________
if [ $((num%2)) -eq 0 ]
then
echo "even"
else
echo "odd"
fi
----------------------------
mathmatical operation using nested if
_______________________________________
echo "---------------------------------"
echo "_______MENU______________________"
echo "1.add"
echo "2.subtract"
echo "3.muliply"
echo "4.divide"
echo "_________________________________"
echo "selelct"
read opt
if [ $opt = 1 ]
then
r=$((n1+n2))
elif [ $opt = 2 ]
then
r=$((n1-n2))
elif [ $opt = 3 ]
then
r=$((n1*n2))
elif [ $opt = 4 ]
then
r=$((n1/n2))
else
echo "invalid choose"
fi
-------------------------------------------------
factorial
_________________________
f=1
i=1
while [ $i -le $n ]
do
f=$((f*i))
i=$((i+1))
done
-------------------------------------------------
telephone bill
________________________
unit=$((clr-opr))
echo "select your tariff plan 100 or 200"
read tariff
case $tariff in
100)
nunit=$((unit-20))
ucharge=$((nunit*2));;
200)
nunit=$((unit-50))
ucharge=$((nunit*1));;
*)
echo "invalid choice....!!"
esac
amount=$((tariff+ucharge))
echo "BILL"
echo "tariff \t unit \t extra \t amt \t bill"
echo "_____________________"
echo "$tariff \t $unit \t $nunit \t $ucharge \t Rs.$amount"
echo "_____________________"
--------------------------------------------------------------
--------------------------------------------------------------
if [ $dt -le 12 ]
then
echo "morning"
else
echo "after noon"
fi
---------------------------------------------------------------
directory or not
_________________
if [ -d $f1 ]
then
echo "$f1.. is a Directory"
else
echo "$f1.. is NOT a Directory"
fi
-------------------------------------------------------------
----------------------------------------------------------
palindrom
_____________
while [ $n -gt 0 ]
do
rem=$((n%10))
rev=$((rev*10+rem))
n=$((n/10))
done
if [ $rev = $a ]
then
echo "palindrom"
else
echo " not palindrom"
fi
-------------------------------------------------------------
largest from 3
________________
-------------------------------------------------------------
sum of digit
____________
while [ $n -gt 0 ]
do
d=$((n%10))
s=$((s+d))
n=$((n/10))
done
echo "sum= $s "