|
|||||||
| 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
|
|||
|
|||
|
Adding variables in a unix script
Hi I am trying to add variables(float values) in a unix script but am getting an error Code:
value=`expr $a + $b + $c` The error I am getting is "expr: non-numeric argument" I guess it has got to something with the decimal points. Plz help |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
look at the arithmetic evaluation section in the manpage for the shell you are using...
(shell calculations are limited to integer values) |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
|
|
#4
|
|||
|
|||
|
Code:
var=$(echo "$a +$b +$c" | bc) |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
ant:/home/vbe $ echo "$A+$B+$C"
3+4+9.5 ant:/home/vbe $ echo "$A+$B+$C"|bc 16.5 |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Thanks a lot....
![]() total=`echo $numone + $numtwo | bc` worked fine. There is also one more prob......The variable sometimes contains "" attached to it also eg "23.45". How to handle this in the addition?It is throwing an error"syntax error on line 1 stdin" ![]() |
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
ant:/home/vbe $ echo $(expr "23.45")+"$A+$B+$C"|bc
39.95 |
| 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 |
| Script that takes in variables, and outputs to another text or script file | orozcom | Shell Programming and Scripting | 1 | 05-19-2009 03:59 PM |
| sqlplus session being able to see unix variables session within a script | 435 Gavea | Shell Programming and Scripting | 2 | 07-03-2006 10:11 AM |
| adding variables for, for loop | jazz | Programming | 3 | 03-13-2006 03:23 AM |
| Adding a New IP Addresses to a SCO Unix Box | dman110168 | IP Networking | 1 | 02-17-2002 12:57 PM |
| adding printer in unix | bong m | UNIX for Dummies Questions & Answers | 2 | 12-07-2000 01:28 PM |
|
|