On Mon, Jul 19, 2004 at 09:50:51AM +0800, alben benavente alteza wrote:
> in a bash script, how do we add two numbers like:
> 
> a=1
> b=2
> 
> c=$a+$b
> 
> echo $c
> 
> my script is treating the numbers as string.

This is more a newbie question, IMHO, so please see
<http://lists.q-linux.com/mailman/listinfo/ph-linux-newbie>.

Anyway, back to the topic, Bash treats all variables as strings, AFAIK.
One approach is to pipe the output to bc, an arbitrary precision
calculator, as in:

    c = `echo "$a+$b" | bc`
    echo $c

I'm sure there are many other ways of doing this, but this one works
pretty well IMO. :)

 --> Jijo

-- 
Federico Sevilla III : jijo.free.net.ph : When we speak of free software
GNU/Linux Specialist : GnuPG 0x93B746BE : we refer to freedom, not price.
--
Philippine Linux Users' Group (PLUG) Mailing List
[EMAIL PROTECTED] (#PLUG @ irc.free.net.ph)
Official Website: http://plug.linux.org.ph
Searchable Archives: http://marc.free.net.ph
.
To leave, go to http://lists.q-linux.com/mailman/listinfo/plug
.
Are you a Linux newbie? To join the newbie list, go to
http://lists.q-linux.com/mailman/listinfo/ph-linux-newbie

Reply via email to