Forum     

Go Back   Digit Technology Discussion Forum > Software > Open Source
Register FAQ Calendar Mark Forums Read

Open Source A place where you can talk to like-minded people about the fastest growing software movement today! Discuss anything and everything about Open Source software and Operating Systems.

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 21-05-2006, 11:11 PM   #1 (permalink)
Alpha Geek
 
Join Date: Feb 2005
Posts: 959
Default mul. in shell script

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
__________________
A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila.
legolas is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 22-05-2006, 03:48 PM   #2 (permalink)
Wise Old Owl
 
vignesh's Avatar
 
Join Date: Jul 2004
Location: Chennai
Posts: 1,659
Default Re: mul. in shell script

Use the read command to get input..
vignesh is offline  
Old 22-05-2006, 10:01 PM   #3 (permalink)
String Phreak
 
mediator's Avatar
 
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,453
Default Re: mul. in shell script

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 !!
mediator is offline  
Old 23-05-2006, 08:39 PM   #4 (permalink)
Alpha Geek
 
Join Date: Feb 2005
Posts: 959
Default Re: mul. in shell script

and thank you very much for that!!! really...

/legolas
__________________
A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila.
legolas is offline  
Old 24-05-2006, 06:46 PM   #5 (permalink)
String Phreak
 
mediator's Avatar
 
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,453
Default Re: mul. in shell script

Oyi....Glad u liked it! Now repute me !!!
mediator is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +5.5. The time now is 03:00 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2