Solved

dividing numbers in unix

Posted on 2014-04-23
5
257 Views
Last Modified: 2014-04-23
Hi
I am trying to divide two numbers , I tried various method but not getting result

I tried
p1= `$(expr $diffcount / $basecount)`
p1= $(expr $diffcount / $basecount)
p1= expr(($diffcount / $basecount))
p1= $expr(($diffcount / $basecount))

diffcount and basecount values are generated by other expressions
I am getting values for those valuables . I am using Korn shell

thanks
0
Comment
Question by:uco
  • 2
  • 2
5 Comments
 
LVL 37

Expert Comment

by:Gerwin Jansen
Comment Utility
You can try using bc instead of expr:

result=$( echo "scale=3 ; $diffcount / $basecount" | bc )
echo $result
0
 

Author Comment

by:uco
Comment Utility
Thanks Jansen , that works, one last one how do we multiply the result with another variable

thanks
0
 
LVL 37

Accepted Solution

by:
Gerwin Jansen earned 500 total points
Comment Utility
Just add it here:

$diffcount * $othervariable / $basecount
0
 

Author Closing Comment

by:uco
Comment Utility
Thanks Jensen
0
 
LVL 19

Expert Comment

by:simon3270
Comment Utility
Also note that in all of your examples there was a space after the "=" sign - there must be no spaces either side of the "=" when assigning values in shell.

Without the space, the second expression would have been what you wanted (as long as you don't mind an integer result).
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now