DIGIT-ARC read-only archive · snapshot: July 23, 2026

mul. in shell script

5 posts · originally from https://geek.digit.in/community/threads/mul-in-shell-script.28679/

L
legolas Original post #1
May 21, 2006 at 11:11 PM
hi,

i am writing a shell script... and in that i wanted to multiply two integer numbers taken from command line(during execution, i mean... with $a and $b) i dont know how to do this... pls help me.. coz when i put directly the numbers, it multiplies, but i havb difficulties when the numbers are got from the command line...

/legolas
vignesh
vignesh #2
May 22, 2006 at 3:48 PM
Use the read command to get input..
mediator
May 22, 2006 at 10:01 PM
Here's a complete shell script dood i made during ma 2nd year !!

********************* Save as shellscript ***********************

#simple division => "`expr $1 / $2`"
if [ -z $1 ] || [ -z $2 ]
then
echo "Two Arguments needed!!";exit
else
echo "Enter Your option"
echo "1) Multipication"
echo "2) Division"
echo "3) Addition"
echo "4) Subtraction"
echo "5) Exit"
while [ 1 ]
do
echo -n "Option : ";read option
case $option in
1)echo "Result = `expr $1 \* $2`";;
2)echo "Result = `echo "$1/$2" | bc -l`";;
3)echo "Result = `expr $1 + $2`";;
4)echo "Result = `expr $1 - $2`";;
5)echo "Ended on : `date`";exit;;
*)echo "Enter one of the given options";;
esac
done
fi

******************* Run as "sh shellscript arg1 arg2" *******************

Problem Solved !!
L
legolas #4
May 23, 2006 at 8:39 PM
and thank you very much for that!!! :) really...

/legolas
mediator
May 24, 2006 at 6:46 PM
Oyi....Glad u liked it! Now repute me !!!