12

How to calculate very long numbers in bash?

param=$(( 3247238523785623478565 + 53453453252345346534563412634 ))

echo $param
3420247196502465471

as we see here, this isn't the right answer because of the limit of integer numbers.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
maihabunash
  • 7,131

1 Answers1

14

Use bc ("an arbitrary precision calculator language"):

param=$(bc <<< '3247238523785623478565 + 53453453252345346534563412634')
choroba
  • 47,233