Simple Shell Script for Additon,mul,division


Pinoy Techie

# Aug/6/ 2011

#scritp for addition mul sub

#you can run this script using bash

#echo are used to display string on terminal or screen

echo -n "Enter No 1:-"

read no1

echo -n "Enter No 2:-"

read no2

echo " "

# expr another way is $[ 1 + 3 ] this stmt work in bash shell not dash shell specially in ubuntu

# u can rewrite below statment ans=$[ $no1 + $no2 ]

ans=`expr $no1 + $no2`

echo "Addition is:= $ans"

ans=`expr $no1 - $no2`

echo "Sub is:= $ans"

ans=`expr $no1 \* $no2`

echo "Mul is := $ans"

# in division u can use `expr $no1 / $no2` but you did't get floating point value

# bash means bourn again shell did't support floating point value

# bc command are used to calculate the division operation bc means basic calculator

# here | means echo command value are used as input in bc command means

#output of echo cmmand are passed in bc command

# scale are used to provide total no of digit after fraction point

# use 'man bc' for more info use bc command in terminal u can exit from bc command using ctr+d or ctr+c

ans=`echo "scale=4; $no1 / $no2" | bc`

echo "Division is:=$ans"

Top Bottom