Addition

Hi all,
I am very new to shell programming and trying to learn out the basics.
I tried this:

$ echo `expr 20 + 30`

and it worked. But when i tried this,it does not work.

$ a=20
$ b=30
$ echo `expr a + b`

The error is:

expr: non-numeric argument

I cant understand why its throwing me this error :frowning:

Pleas explain and solve my problem

Should be echo `expr $a + $b`

oops..............i forget that $ i used to read the contents of a variable............

sorry my mistake

thank you for the help

have a nice day :slight_smile:

Split a Car Rental and a Hotel Bill for a week with a co-worker?

echo -n $;echo "scale=2; 408.55+1008.56/2" | bc

$912.83

or

expr `echo "digits_go_here" | sed -e 's/[0-9]/ + &/g' -e 's/^ +//g'`

Simple addition and subtraction problems:

echo "1+1" | bc
or
echo $(( 1+1 ))