How Do You Sum in Linux?
Contents

How do you add numbers in Linux?

Use the following syntax to calculate the sum of two integers in a shell script:

  1. Using expr command with quotes sum=`expr $num1 + $num2`
  2. Use expr command inclosed with brackets and start with dollar symbol. sum=$(expr $num1 + $num2)
  3. This is my preferred way to directly with the shell. sum=$(($num1 + $num2))

How do you sum in Shell?

num1=1232 num2=24 num3=444 . . . let SUM=$num1+num2+num3………

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest