Thursday 29 December 2011

Shell Script Programs

1.Shell Script for Arithmetic Calculations for Both integer and decimal values


#!/bin/bash
#i="y"
echo "enter 2 numbers"
read n1
read n2
#while [ $i = "y" ]
#do
echo "enter"
echo "1 for addition"
echo "2 for subtraction"
echo "3 for multiplication"
echo "4 for division"
read n
if [ $n = 1 ]
then
echo " $n1 + $n2" | bc
elif [ $n = 2 ]
then
echo " $n1 - $n2" | bc
elif [ $n = 3 ]
then
echo " $n1 * $n2" | bc
elif [ $n = 4 ]
then
echo "scale=2; $n1 / $n2" | bc
else
echo "invalid choice"
fi