Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I divide in the Linux console?

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?

like image 265
kman99 Avatar asked Jul 06 '09 17:07

kman99


People also ask

How do you float a division in bash?

While you can't use floating point division in Bash you can use fixed point division. All that you need to do is multiply your integers by a power of 10 and then divide off the integer part and use a modulo operation to get the fractional part.

How do I use console in Linux?

They all can be accessed using the key combination Ctrl + Alt + FN#Console. For example, the Console #3 is accessed by pressing Ctrl + Alt + F3. Note The Console #7 is usually allocated to the graphical environment (Xorg, etc.). If you are running a desktop environment, you may want to use a terminal emulator instead.


1 Answers

In the bash shell, surround arithmetic expressions with $(( ... ))

$ echo $(( 7 / 3 )) 2 

Although I think you are limited to integers.

like image 125
dave4420 Avatar answered Sep 28 '22 06:09

dave4420