![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| addition | email-lalit | Shell Programming and Scripting | 2 | 08-06-2008 06:58 PM |
| Addition problem | onlyroshni | Shell Programming and Scripting | 2 | 12-10-2007 02:11 PM |
| Unix addition ( Row wise) | gauravgoel | Shell Programming and Scripting | 3 | 05-17-2007 05:27 AM |
| floating point addition | ravi raj kumar | Shell Programming and Scripting | 8 | 12-22-2006 02:47 AM |
| Addition of numbers in unix | asinha63 | Shell Programming and Scripting | 3 | 03-14-2006 12:38 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Simple addition, help.
I add up the number of args that are not blank. It works, but the printout is a string that just keep concatenating on +1. So Ex. it goes through input of: bob toto " " tom ...I get 0+1+1+1, when all I want is 3. Any help is appreciated. Code:
count=0 for name in $* do if [ "$name" != "" ]; then count="$count+1" fi done echo $count |
|
||||
|
If you're in ksh or bash, you can add stuff using $(( )) operator:
i=1 echo $(( $i + 1 )) Nice thing with this construction is that you can nest the math: a=1 b=10 echo $(( $a + $(( $b + 1 )) )) /fimblo |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|