I need to sum up all those three numbers, after storing them in three variables (say var1, var2, var3).
I used both expr and BC, but they didn't work for me.
But, I am not able to sum up them, as I don't have any idea how to take those (+) and (-) sign in account while summing up.
I posted a simplified version to get the basic idea. Actually, I am reading those values from a file.
The datas are in the following format in a file (say result.txt):
Thanks for all your prompt and valuable reponse.
But, in actual scenario, I have to read the data from the file using a while-do-done loop.
Each line I read from the file contains some data, from where I am using grep+cut to read some specific portion from few specific records.And, that specic portion contains those (+)ve and (-)ve values.
So, please let me know is it possible to sum up those numbers in the above scenario?
I ahve to use while/read and grep/cut...because before performing these arithmatic opertaion I need to do a lot more tasks on the source file.
So, if possible please suggest me how to do the arithmatic operation...while using the while/read and grep/cut.
It works with any Posix shell (so /usr/xpg4/bin/sh on Solaris).
But this should just work in Bourne shell as well, shouldn't it? Did you try?
-----
edit: Ah, I see you did not mean the loop but the second part: because of the $() .
Then you can use: