• BASH > faire des calculs mathématiques

      a=1 ; b=17 ; bc <<< "$a*100/$b"

       

       

      var3=`bc <<< "scale=2; $var2"`

      On the other hand, $var1 and $var2 won’t store float (bash doesn’t manage them), so you bc instead.

      diff=$(($epoc2-$epoc1))
      var1=$(bc <<< "scale=3 ; $diff / 60")
      var2=$(bc <<< "scale=3 ; $var1 / 57")
      var3=$(bc <<< "scale=2; $var2")

       

       

      bc <<< 'scale=2; 100/3'
      33.33

      UPDATE 20130926 : you can use:

      bc -l <<< '100/3' # saves a few hits
      33.33333333333333333333

       

 

Aucun commentaire

 

Laissez un commentaire