How do I divide in the Linux console?

后端 未结 12 1981
情话喂你
情话喂你 2020-12-25 10:41

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?

12条回答
  •  攒了一身酷
    2020-12-25 11:19

    Better way is to use "bc", an arbitrary precision calculator.

    variable=$(echo "OPTIONS; OPERATIONS" | bc)
    

    ex:

    my_var=$(echo "scale=5; $temp_var/100 + $temp_var2" | bc)
    

    where "scale=5" is accuracy.

    man bc 
    

    comes with several usage examples.

提交回复
热议问题