|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
how to use the expr expression in UNIX?
Hi all,
I'm facing a problem with "expr" command while calculating value inside the shell script (c shell). if i passed direct number to expr command its working but if passed value through variable its not working. For example: set Result=`expr 500 + 50` echo $Result output : 550 But if i pass value through variable its not working $A=150.15 $B=25.20 set Results=`expr $A + $B` echo $Results output = 0 Could you please anyone help me on this? Thanks MPS |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
expr only accepts whole number arguments - integers.
That is why you got zero. It will work with environment variables. |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Quote:
Quote:
|
|
#4
|
||||
|
||||
|
How can we calculate the floating data with expr command?
Thanks for your reply,
How can we calculate the floating data with expr command? Eg: $A=150.15 $B=25.20 set Results=`expr $A + $B` echo $Results Could you please send me the actual solution for this? Thanks MPS |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Quote:
Quote:
And call it with, for example: Code:
calc '3.2 + 4.3' |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
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 02:52 PM |
| error: initializer expression list treated as compound expression | arunchaudhary19 | Programming | 12 | 11-16-2007 05:44 AM |
| expr | Nathe | UNIX for Dummies Questions & Answers | 5 | 01-22-2004 06:49 PM |
| Regular Expression + Aritmetical Expression | Z0mby | Shell Programming and Scripting | 2 | 05-21-2002 10:59 AM |
| compound expression in unix | spalmer | UNIX for Dummies Questions & Answers | 3 | 10-19-2001 12:04 PM |
|
|