## Arithmetic in Korn Shell

### Arithmetic in Korn Shell

Is it possible to do simple arithmetic in Korn Shell with decimal
numbers?
I'm trying to add 0.1 to a number such as 1.3; is this possible?

### Arithmetic in Korn Shell

> Is it possible to do simple arithmetic in Korn Shell with decimal
> numbers?
> I'm trying to add 0.1 to a number such as 1.3; is this possible?

echo "0.1 1.3+pq" | dc

### Arithmetic in Korn Shell

> > Is it possible to do simple arithmetic in Korn Shell with decimal
> > numbers?
> > I'm trying to add 0.1 to a number such as 1.3; is this possible?

> echo "0.1 1.3+pq" | dc

Or, if you're not a fan of RPN, you can use bc

echo "0.1+1.3"|bc

### Arithmetic in Korn Shell

> ...

"Decimal" numbers? Do you not mean "floating point notation"?

You did no mention the ksh version, so the answer is: yes, for ksh93.
The answer for ksh88 is still yes, however, the fractional part of the
floating point number will be truncated.

-Brian

### Arithmetic in Korn Shell

>> > Is it possible to do simple arithmetic in Korn Shell with decimal
>> > numbers?
>> > I'm trying to add 0.1 to a number such as 1.3; is this possible?

>> echo "0.1 1.3+pq" | dc

> Or, if you're not a fan of RPN, you can use bc

> echo "0.1+1.3"|bc

And if you have a lot of computation to do,  I would suggest
starting bc as a co_process:

bc |&

print -p "0.1+1.3"

...

print -p "quit"

Opinions expressed herein are my own and may not represent those of my employer.

### Arithmetic in Korn Shell

|> Is it possible to do simple arithmetic in Korn Shell with decimal
|> numbers?
|> I'm trying to add 0.1 to a number such as 1.3; is this possible?
|>

A=0.1
B=1.3
let C=A+B
echo \$C

--
Views expressed are personal and not necessarily shared by my employer.

### Arithmetic in Korn Shell

Quote:> > Is it possible to do simple arithmetic in Korn Shell with decimal
> > numbers?  I'm trying to add 0.1 to a number such as 1.3; is this
> > possible?

Quote:> A=0.1
> B=1.3
> let C=A+B
> echo \$C

...if you happen to be using ksh93.

--
Peter Samuelson
<sampo.creighton.edu!psamuels>

### Arithmetic in Korn Shell

> > > Is it possible to do simple arithmetic in Korn Shell with decimal
> > > numbers?  I'm trying to add 0.1 to a number such as 1.3; is this
> > > possible?

> > A=0.1
> > B=1.3
> > let C=A+B
> > echo \$C

> ...if you happen to be using ksh93.

> --
> Peter Samuelson
> <sampo.creighton.edu!psamuels>

If not,

A=0.1
B=1.3

C=`bc << EOF
\$A + \$B
EOF`

echo \$C

Hello all,

I need to perform date arithmetic in my Korn shell script. Examples would
be NewDate=(CurrentDate - 2 days) and NewDate=(CurrentDate + 2 months).
Any suggestions on how this can be done would be highly appreciated.

TIA
Pushpendra