how do I get the value of expr with ksh | Unix Linux Forums | UNIX for Advanced & Expert Users

 Member Name Remember Me? Password

 UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

# how do I get the value of expr with ksh

## UNIX for Advanced & Expert Users

#1
08-24-2001
 krishna Registered User Join Date: Aug 2001 Last Activity: 3 August 2007, 4:25 AM EDT Posts: 60 Thanks: 0 Thanked 0 Times in 0 Posts
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
Sponsored Links
#2
08-24-2001
 Michael Registered User Join Date: May 2001 Last Activity: 8 November 2001, 8:00 AM EST Location: Germany Posts: 15 Thanks: 0 Thanked 0 Times in 0 Posts
Hi Krisna,

try it with "let"

example:

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

k=900

greetings
Sponsored Links
#3
08-25-2001
 patvdv Registered User Join Date: Jul 2001 Last Activity: 14 March 2003, 5:08 AM EST Location: Belgium Posts: 83 Thanks: 0 Thanked 0 Times in 0 Posts
KSH Maths

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

#4
08-26-2001
 rwb1959 Registered User Join Date: Aug 2001 Last Activity: 16 October 2009, 2:04 PM EDT Location: Virginia, USA Posts: 438 Thanks: 0 Thanked 1 Time in 1 Post
using expr

"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.
Sponsored Links

 Thread Tools Search this Thread Search this Thread: Advanced Search Display Modes Linear Mode

 More UNIX and Linux Forum Topics You Might Find Helpful Thread Thread Starter Forum Replies Last Post jagari Shell Programming and Scripting 6 02-24-2012 05:25 AM Mad van Bert UNIX for Dummies Questions & Answers 1 09-06-2011 03:28 AM jackel7777 Shell Programming and Scripting 1 07-29-2011 10:29 PM ashok.g Shell Programming and Scripting 2 12-03-2009 06:42 AM saikumarm80 Red Hat 3 01-05-2009 02:52 PM

All times are GMT -4. The time now is 12:44 AM.