Get ceiling integer from number in linux (BASH)

后端 未结 13 1954
陌清茗
陌清茗 2020-12-01 04:54

How would I do something like:

ceiling(N/500)

N representing a number.

But in a linux Bash script

13条回答
  •  [愿得一人]
    2020-12-01 05:36

    This is a simple solution using Awk:

    If you want the ceil of ($a/$b) use

    echo "$a $b" | awk '{print int( ($1/$2) + 1 )}'
    

    and the floor use

    echo "$a $b" | awk '{print int($1/$2)}'
    

    Note that I just echo the dividend '$a' as the first field of the line to awk and the divisor '$b' as the second.

提交回复
热议问题