Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shell script + numbers sum

Tags:

bash

ksh

what the best simple elegant way to sum number in ksh or bash my example is about let command , but I want to find better way to summary all numbers

for example

num1=1232
num2=24 
num3=444
.
.
.

let SUM=$num1+num2+num3.........
like image 541
lidia Avatar asked Sep 03 '10 08:09

lidia


1 Answers

How about:

num1=1232
num2=24 
num3=444
sum=$((num1+num2+num3))
echo $sum # prints 1700
like image 148
codaddict Avatar answered Sep 18 '22 19:09

codaddict