$cat add_variables_02.shExecute in a shell
nv=$((ov+3)); echo $nv
((nv=ov+3)); echo $nv
nv=$ov+3; echo $nv
nv=`expr $ov+3`; echo $nv
nv=`expr $ov + 3`; echo $nv
$bash add_variables_02.shThe first two methods nv=$((ov+3)) or ((nv=ov+3)) are faster than the fifth method nv=`expr $ov + 3` as the former uses bash's own feature and the later runs an external command in a subprocess.
Also, note that spaces are needed before and after the '+' character when expr is used.
Tested in Debian Wheezy machine using bash 4.2-1
- info coreutils 'expr invocation'
- man expr
Special thanks to the anon 2011-08-24 5:06 AM for providing the first two methods.