Results 1 to 3 of 3
I'm trying to create a script that will convert b/s to kb/s. To convert to kb/s, I must divide it to 1000 b/s. However, the answer does not contain the ...
- 12-01-2007 #1Linux Newbie
- Join Date
- Mar 2006
- Posts
- 101
How to display remainder in Bash script
I'm trying to create a script that will convert b/s to kb/s. To convert to kb/s, I must divide it to 1000 b/s. However, the answer does not contain the remainder. When I do "expr 5 / 3", it shows only 1 (suppose to be 1.6). Doesn't show the remainder .6.
I search in Google and it says the "%" is remainder of a division. But when I do expr 5 % 3, it shows "2". It suppose to be 6, am I right?
Any inputs,
- 12-01-2007 #2Linux User
- Join Date
- Jun 2007
- Posts
- 318
Code:echo "scale=3; 5/3" | bc
- 12-01-2007 #3Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi, packets.
The reason for this is hidden in the page info coreutils expr:
This is an important piece of information, omitted from man expr, frustratingly as in many instances of man pages on GNU/Linux.Code:... Operands are either integers or strings. ...
So in the future, you may find it fruitful to consult your info and man pages ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


Reply With Quote