we have written a simple shell script
cd location\address
var1='grep -w -c exception server.log
var2='grep -w -c exception server.log.1
var3= $var1 + $var2
echo $var3
echo $var3
echo 'addition of exception : ' $var3
Output:
240
82
240+82
How to get the summation properly
There are multiple ways to perform arithmetic in UNIX shells, however, before I get into that you need to realize that unless your shell is just different than most shells, you need to define variables as such without whitespace between the variable name, the
=
, or the value:var1='abc'
For this, I'm going to assume that you're using bash
bc
command should workTo help you get started, here's an annotated, syntactically correct version of your code that should work in all POSIX-compatible shells (e.g.,
bash
):General tips:
man
pages.bash
, probably the most widely used POSIX-compatible shell: