The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



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.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to use expr saikumarm80 Red Hat 3 01-05-2009 03:52 PM
expr question low90s UNIX for Dummies Questions & Answers 3 04-29-2008 10:52 AM
expr command madhu_aqua14 UNIX for Dummies Questions & Answers 5 03-05-2007 06:26 PM
expr Nathe UNIX for Dummies Questions & Answers 5 01-22-2004 07:49 PM
expr command wolf UNIX for Dummies Questions & Answers 2 07-31-2001 02:43 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-24-2001
krishna krishna is offline
Registered User
  
 

Join Date: Aug 2001
Posts: 60
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
  #2 (permalink)  
Old 08-24-2001
Michael Michael is offline
Registered User
  
 

Join Date: May 2001
Location: Germany
Posts: 15
Hi Krisna,

try it with "let"

example:

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

k=900

greetings
  #3 (permalink)  
Old 08-25-2001
patvdv's Avatar
patvdv patvdv is offline
Registered User
  
 

Join Date: Jul 2001
Location: Belgium
Posts: 83
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 (permalink)  
Old 08-26-2001
rwb1959's Avatar
rwb1959 rwb1959 is offline
Registered User
  
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:05 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0