Solved

dividing numbers in unix

Posted on 2014-04-23
5
270 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 38

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 38

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
High Bandwidth Usage 6 76
Why  my code (program) build with old compiler? 11 79
Moving from Mcrypt to OpenSSL 18 48
Redhat upgrade 1 27
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…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

820 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