Find the answer to your Linux question:
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 ...
  1. #1
    Linux 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,

  2. #2
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    Code:
    echo "scale=3; 5/3" | bc

  3. #3
    drl
    drl is online now
    Linux Engineer drl's Avatar
    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:
    Code:
    ... Operands are either integers or strings. ...
    This is an important piece of information, omitted from man expr, frustratingly as in many instances of man pages on GNU/Linux.

    So in the future, you may find it fruitful to consult your info and man pages ... cheers, drl
    Welcome - 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 )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...