dividing numbers in unix

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
ucoAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Gerwin Jansen, EE MVEConnect With a Mentor Topic Advisor Commented:
Just add it here:

$diffcount * $othervariable / $basecount
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
You can try using bc instead of expr:

result=$( echo "scale=3 ; $diffcount / $basecount" | bc )
echo $result
0
 
ucoAuthor Commented:
Thanks Jansen , that works, one last one how do we multiply the result with another variable

thanks
0
 
ucoAuthor Commented:
Thanks Jensen
0
 
simon3270Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.