Sponsored Content
Full Discussion: Simple addition, help.
Top Forums Shell Programming and Scripting Simple addition, help. Post 302239346 by Bandit390 on Tuesday 23rd of September 2008 11:36:50 AM
Old 09-23-2008
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

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Addition problem

Hello Seniors!!! I am trying to add to lines on a file which is delimited by character "|". input.txt Desired Output file should give simple addition. output.txt Can some one provide me simple awk solution to this. M struggling to solve this using awk & for loop inside awk. Thanks... (2 Replies)
Discussion started by: onlyroshni
2 Replies

2. Shell Programming and Scripting

addition

Hi all, I am new to perl. I need help adding bunch of numbers. I have a file look like this: 1 1 2 1 2 3 1 2 3 4 1 (2 Replies)
Discussion started by: email-lalit
2 Replies

3. UNIX for Dummies Questions & Answers

addition in sh shell

I have to create un counter and I am unable to do an additition: #!/bin/sh count=$1 while ] do echo $count $count=$count+$1 done (1 Reply)
Discussion started by: cfg
1 Replies

4. Shell Programming and Scripting

Help with addition

Hi all, I am getting following output by using commands like sort, uniq and awk to the standard output. 110 d 40 a 59 c 9 b 3 e Now at the end I would like to add all the numbers in column 1 and display the count of all numbers i.e. (110 + 40 + 59 + 9 + 3). Also the output may... (3 Replies)
Discussion started by: tenderfoot
3 Replies

5. Shell Programming and Scripting

Addition

Hi all, I am very new to shell programming and trying to learn out the basics. I tried this: $ echo `expr 20 + 30` and it worked. But when i tried this,it does not work. $ a=20 $ b=30 $ echo `expr a + b` The error is: expr: non-numeric argument I cant understand why its... (3 Replies)
Discussion started by: gautamshaw
3 Replies

6. Shell Programming and Scripting

Substitution/Addition

Hi I need to do the following substitution I have to look for line starting with ABC and add 4 ":" before the first occurence of "+"in that line Input ABC:12:Lambert:C278472:1357:0:0:0:0:2:N::::N:9045123:NAP::+DEF output ABC:12:Lambert:C278472:1357.00:0.00:0:0:0:2:N::::N:9045123:NAP::::::+DEF... (5 Replies)
Discussion started by: mad_man12
5 Replies

7. Shell Programming and Scripting

Need help on addition in shell

i need shell script to add to numbers #!/usr/bin/sh a=1310601600 ------> epcho time of Thu, 14 Jul 2011 00:00:00 UTC b=864000 -------> 10 days in sec c=`expr $a+$b` echo $c----1311465600> this output i will use this value to delete the data from MySQL db next i need to set... (3 Replies)
Discussion started by: sreedhargouda
3 Replies

8. Shell Programming and Scripting

addition of decimal no

a=10.00 pattern=-11.00 b=`echo "$a $pattern" | awk ' printf("%d\n", $1 + $2)'` echo $b not working, also trined bc ,dc but thats not on my m/c. also expr not supporting. any clue? (6 Replies)
Discussion started by: saluja.deepak
6 Replies

9. Shell Programming and Scripting

addition of two numbers

by the script, two files Q1 and Q2 will be generated on the system. Q1 will contain an integer number and Q2 also contain an integer number. i would like to add those numbers and put into new file. excerpt from my script 22 subcount=`echo $dir/Q$qid.txt` + `echo $dir/Q$qid.txt` 23 echo... (1 Reply)
Discussion started by: lookinginfo
1 Replies

10. Shell Programming and Scripting

Addition of new line

Hi I have a file whose contents are as follows: sorce1 LEN assumption 695 3570 0.770047 - . ID=f000001.1;source_id=A.off_LEN_10008424; sorce1 LEN descriptive 3334 3570 . - 0 Parent=f000001.1; sorce1 LEN ... (8 Replies)
Discussion started by: sa@@
8 Replies
DECLAR(3)							 GENPAT functions							 DECLAR(3)

NAME
DECLAR, GENPAT Package ORIGIN
This software belongs to the ALLIANCE CAD SYSTEM developed by the ASIM team at LIP6 laboratory of Universite Pierre et Marie CURIE, in Paris, France. Web : http://asim.lip6.fr/recherche/alliance/ E-mail : alliance-users@asim.lip6.fr SYNOPSYS
DECLAR("ident",":nb_space","format",mode,size,option); PARAMETERS
ident External connector, internal observing points or register's name. For the hierarchical descriptions, the path-name of the inter- nal observing points or registers must be specified by the syntax : instance1.instance11.name . nb_space Specify the number of blank space between each group of value associated to the connectors, signals or registers in the output file. 0,1,2,3,4,5,6,7,8,9 or nothing. format Specify the format that will be used to represent the value associated to the connectors, signals or registers. X for Hexadeci- mal, O for Octal and B for Binary. mode Specify the type of the connectors. IN for Input, OUT for Output, INOUT for Input/Output, SIGNAL for internal observing point, REGISTER for register. IN, OUT, INOUT, SIGNAL, REGISTER are constants (defines) provided by genpat. size Specify the size of the bused connectors : empty ("") for the scalar connectors, "nb1" for the numbered connectors, "nb1 TO nb2" or "(nb1 TO nb2)" (nb1 < nb2), "nb1 DOWNTO nb2" or "(nb1 DOWNTO nb2)" (nb2 < nb1) for the vectors. Where nb1 and nb2 are integer. option Specify options of the connector. "S" for a spied connector, empty ("") for a normal connector. DESCRIPTION
Describes a set of connectors, signals or registers of the same format, size and mode. EXAMPLE
DECLAR("a", ":2", "X", OUT, "3 DOWNTO 0", "S"); describes : a 3, a 2, a 1, a 0 format : Hexadecimal. mode : Output. option : Spied connector. the group is separated of the others with 2 blank spaces. result : out a(3 downto 0) X spy ;;; DECLAR ("toto", ":", "O", INOUT, "7 TO 11", ""); describes : toto 7, toto 8, toto 9, toto 10, toto 11. format : Octal. mode : Input/Output. option : none. the group is separated of the following with 0 blank space. result : inout toto(7 to 11) O ; DECLAR ("ck", ":2", "B", IN, "", ""); describes : ck. format : Binary. mode : Input. option : none. the port is separated of the following with 2 blank spaces. result : in ck ;;; DECLAR ("accu.f", ":", "B", SIGNAL, "", "S"); describes : accu.f . format : Binary. mode : Signal. option : Spied connector. the signal is separated of the following with 0 blank space. result : signal accu.f spy ; DECLAR ("accu.reg", ":1", "B", REGISTER, "(3)", ""); describes : accu.reg . format : Binary. mode : Register. option : none. the signal is separated of the following with 1 blank space. result : register accu.reg(3) ;;;; WARNING
The DECLAR function from the 4.0 release have a new parameter (option). SEE ALSO
ARRAY(3), genpat(1), pat(5) BUG REPORT
This tool is under development at the ASIM department of the LIP6 laboratory. We need your feedback to improve documentation and tools. ASIM
/LIP6 October 1, 1997 DECLAR(3)
All times are GMT -4. The time now is 05:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy