[Fwd: [ale] simple math in bash]

Geoffrey Myers geof at abraxis.com
Mon Nov 17 23:20:20 EST 1997


Sent the following to Mike and not to the list....

> Mike Kachline wrote:
>
> > On Sat, 15 Nov 1997, David Hamm wrote:
> >
> > > I can't remember how to do simple math in bash.  I used to know but I cant find
> > <snip>
> >
> >         Don't know whether there is an easier way, but, I have always
> > used "dc" to do math in shell scripts. Ex, adding 1 + 1 would be:
> >
> > echo "1 1 + p q" | dc
>
> I'm actually a ksh guy, but I tried the following which I use often in ksh and it
> works in bash:
>
> $ echo $(((1 + 3) * 14))
>
> 56
>
> That's pretty simple, although you can get complex.
>
> You can also do:
>
> $ foo=$(((1 + 3) * 14))
> $ echo $foo
> 56
>
> ksh is a bit different in that you can do this like:
>
> ((foo=(1 + 3) * 14))
>
> >                                                         - Mike
> > ============================================================================
> > Michael Kachline - CS, Georgia Tech
> > kachline at cc.gatech.edu
> > http://brightstar.gt.ed.net/kachline/
> > ============================================================================
>
> --
> Until later: Geoffrey           geof at abraxis.com



--
Until later: Geoffrey           geof at abraxis.com






More information about the Ale mailing list