I have to variables and I want to find the value of one divided by the other. What commands should I use to do this?
+5
A:
Check this article: http://www.basicallytech.com/blog/index.php?/archives/23-command-line-calculations-using-bc.html
freitass
2009-07-06 17:08:21
A:
I assume that by Linux console you mean Bash.
If X
and Y
are your variables, $(($X / $Y))
returns what you ask for.
Paolo Capriotti
2009-07-06 17:12:36
You don't need the $'s for the variables
Draemon
2009-07-06 17:14:03
+2
A:
In the bash shell, surround arithmetic expressions with $(( ... ))
$ echo $(( 7 / 3 ))
2
Although I think you are limited to integers.
Dave Hinton
2009-07-06 17:12:44
A:
Example of integer division using bash to divide $a by $b:
echo $((a/b))
Draemon
2009-07-06 17:13:11
+1
A:
In bash, if you don't need fractions in your division, you can do:
>echo $((5+6))
11
>echo $((10/2))
5
>echo $((10/3))
3
Mark Rushakoff
2009-07-06 17:13:38
+1
A:
I still prefer using dc, which is an RPN calculator, so quick session to divide 67 by 18 with 4 digits precision would look like
>dc
4k
67
18/p
3.7222
q
>
Obviously, much more available: man dc
libjack
2009-07-06 18:51:15