Adding 2 numbers

I would like to write a script with BASH to add two numbers (integer) and write the result to the standard output. Please help!

use the bc command or use awk.
assuming two numbers in a file called file1

cat file1 | awk ' printf("%d\n", $1 + $2)'

this short script works in sh & ksh, I assume bash as well.

let i=0
let i=$1+$2
echo $i

expr $var1 + $var2

There are loads of ways to do it.

Another is

echo "1 + 2" | bc

Matt

First of all, thank you very much for help, but I still have problems:

  • I have to write my script without bc or dc commands.

  • I would like to sum very-very big numers (600 characters long).
    It doesn't work with let, expr, or awk. (because of overflow)

Have you got any idea, how to solve this problem?

Thank you!

Just try Gawk!
It performs in superior to other awk's clones.

echo "scale=600;1/7"|bc
.1428571428571428571428571428571428571428571428571428571428571428571\
42857142857142857142857142857142857142857142857142857142857142857142\
85714285714285714285714285714285714285714285714285714285714285714285\
71428571428571428571428571428571428571428571428571428571428571428571\
42857142857142857142857142857142857142857142857142857142857142857142\
85714285714285714285714285714285714285714285714285714285714285714285\
71428571428571428571428571428571428571428571428571428571428571428571\
42857142857142857142857142857142857142857142857142857142857142857142\
857142857142857142857142857142857142857142857142857142857