Tuesday, April 19, 2011

To add two integers in Shell Script

Adding two numbers are not as easy as i=$i+1 in shell script. It is done using different ways. Here is one example :-

#!/bin/sh
i=1
while [ $i -lt 3 ]
do
echo "test"
i=$(($i+1))
echo $i
done

1 comment:

Vikrant said...

I am Still not getting catch.

Why don't we directly have i=$(($i+x))

AM i missing something