addition of two numbers

by the script, two files Q1 and Q2 will be generated on the system. Q1 will contain an integer number and Q2 also contain an integer number. i would like to add those numbers and put into new file.

excerpt from my script

22 subcount=`echo $dir/Q$qid.txt` + `echo $dir/Q$qid.txt`
23 echo $subcount > $dir/s1.txt

by running the full script i am getting the following error

./test.sh[22]: +: not found [No such file or directory]

thanks in advance

1) Shell arithmetic doesn't work that way. You can't just 'A=B+C'.
2) echo doesn't work that way. You're printing filenames.

So you're ending up with a filename like "/path/to/file1 + /path/to/file2".

How about:

awk '{ T+=$1 }END{print T}' /path/to/file1 /path/to/file2 > file3

---------- Post updated at 02:38 PM ---------- Previous update was at 02:37 PM ----------

If you need to do it in pure shell, you get:

read N1 < /path/to/file1
read N2 < /path/to/file2

N3=`expr $N1 + $N2` # any bourne shell can do this

N3=$((N2+N1)) # More efficient KSH/BASH version

echo $N3 > file3