Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google site



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-22-2004
Registered User
 

Join Date: Dec 2003
Posts: 15
Unhappy expr

Hello!

I want to evaluate some mathematical expressions in a script and I try to use 'expr' command.
Unfortunatally, when I have, for example,
expr 8.2 + 6
the result is 'expr: non-numeric argument'
Why ?
I work on SunOs 5.7.

Thanks in advance
Nathe
Sponsored Links
  #2 (permalink)  
Old 01-22-2004
Advisor
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,623
Seems like expr only accepts integers as operands.
  #3 (permalink)  
Old 01-22-2004
Registered User
 

Join Date: Dec 2003
Posts: 15
but when I read the man of expr, it's written:
DESCRIPTION
Concatenates arg's (adding separator spaces between them),
evaluates the result as a Tcl expression, and returns the
value. The operators permitted in Tcl expressions are a
subset of the operators permitted in C expressions, and they
have the same meaning and precedence as the corresponding C
operators. Expressions almost always yield numeric results
(integer or floating-point values). For example, the
expression
expr 8.2 + 6
evaluates to 14.2. Tcl expressions differ from C expres-
sions in the way that operands are specified. Also, Tcl
expressions support non-numeric operands and string com-
parisons.



So it should work, no ?
  #4 (permalink)  
Old 01-22-2004
Advisor
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,623
What shell scripting are you trying to write actually? It sounds from the first post that you are writing a plain sh-like scripting using expr(1), but the manpage you quoted is a TCL manpage that describes expr in TCL, which accepts floating point arithmetic. If you are not dealing with TCL at all then you have simply read the wrong manpage.
  #5 (permalink)  
Old 01-22-2004
Registered User
 

Join Date: Dec 2003
Posts: 15
Well, I think you are right... I try to write a csh script. I don't know why I have the TCL notice for expr instead of sh one. I work in a standard cmdtool window...

Thank you
Nathe
  #6 (permalink)  
Old 01-22-2004
fpmurphy's Avatar
Moderator
 

Join Date: Dec 2003
Location: Florida
Posts: 2,101
expr does not support floating point numbers.

One way around this is to use a shell that does support
floating point calculations. One such shell is ksh93. Another
is bash.

Another way is to make use of the bc(1) utility e.g.

result=`echo"8.2 + 6" | bc`

- Finnbarr
Sponsored Links
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 Off


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
how do I get the value of expr with ksh krishna UNIX for Advanced & Expert Users 3 08-26-2001 02:51 PM
expr command wolf UNIX for Dummies Questions & Answers 2 07-31-2001 02:43 AM



All times are GMT -4. The time now is 07:41 AM.


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-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0