----- Original Message ----- 
From: "Federico Sevilla III" <[EMAIL PROTECTED]>
To: "Philippine Linux Users Group Mailing List" <[EMAIL PROTECTED]>
Sent: Monday, July 19, 2004 10:08 AM
Subject: Re: [plug] bash script question


> 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. :)

either $(( EXPRESSION )) or $[ EXPRESSION]

c = $(( $a + $b))   or c = $[ $a + $b]
echo $c

for modulo use % (percent sign)

fooler.
--
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