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?

> 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?

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

echo "0.1+1.3"|bc

> ...

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

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

starting bc as a co_process:

bc |&

print -p "0.1+1.3"

read -p ans

...

print -p "quit"

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

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

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?

...if you happen to be using ksh93.Quote:> A=0.1

> B=1.3

> let C=A+B

> echo $C

--

Peter Samuelson

<sampo.creighton.edu!psamuels>

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

A=0.1

B=1.3

C=`bc << EOF

$A + $B

EOF`

echo $C

1. Date arithmetic in Korn shell

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

3. arithmetic substitution in while loop in MKS Korn shell

4. ATI Mach 64 PCI graphics card and XFree86 ver. 3

6. Changing File Names With SED

7. best korn shell resources and is there a korn shell faq

8. PATCH: remove __NO_VERSION__ in mtd

9. Trying to run nohup from Korn shell but getting Bourne shell errors

10. c-shell script won't run from korn-shell / SETUID

12. Shell Compilers, specifically Korn Shell

13. Telling Bourne shell from Korn shell at start-up

8 post • Page:**1** of **1**