Solved

dividing numbers in unix

Posted on 2014-04-23
5
265 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, EE MVE
ID: 40018642
You can try using bc instead of expr:

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

Author Comment

by:uco
ID: 40018698
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, EE MVE earned 500 total points
ID: 40018720
Just add it here:

$diffcount * $othervariable / $basecount
0
 

Author Closing Comment

by:uco
ID: 40018725
Thanks Jensen
0
 
LVL 19

Expert Comment

by:simon3270
ID: 40018797
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

809 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