how do I get the value of expr with ksh

Hi,

I have written a korn shell script to compute the value of k.

formulae :

a=10
b=20
c=30
k=(a+b)*c

my shell script is :

a=10
b=20
c=30
k=`expr (($a + $b ) * $c )`
echo $k

### here paranthesis ( ) not accepting by expr function.
### if i remove paranthesis, the value will be 610(wrong)
### but the actual value should be 900

please give me solution to kkodava@maxis.com.my

thanks

krishna

Hi Krisna,

try it with "let"

example:

let k="($a + $b) * $c"

k=900

:slight_smile: greetings

Why using 'expr' if you can use the built-in KSH math functions instead:

a=10
b=20
c=30
k=$ ((($a+$b)*$c )))
echo $k

"expr" evaluates 2 and only 2 expressions.
In order to accomplish what you want to do
using "expr" you need to nest expr's and
of course, remember to "escape" the speecial
characters. An example would be...

echo `expr \`expr 1 + 2\` \* 3`

This expression, when run at the command
prompt, should yield 9. Of course, if you
are using ksh and not planning on running
a different shell, I would stick with the
ksh built-in capabilities.