Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 05-28-2012
Registered User
 
Join Date: Aug 2011
Location: India
Posts: 74
Thanks: 0
Thanked 1 Time in 1 Post
How to implement the counter in loop?

Hi,

I am working on a script where I need to add one functionality i.e. to could the number of tar files at particular location...but the script is working in below way.
1) create sandbox
2) Drop old member function
3) addmember function
4) Apply checkpoint lable
5) Resync operation(This resync operation occurs at particlar location
Code:
 /mnt/projects/temp/

and script runs in loops..it fetchs the data
from some particular file

Code:
stp/wsSTP:app:STP_12_02_01_00_RC01.tar.gz
stp/gwSTP:web:STP_12_02_01_00_RC01.tar.gz
stpbatch:app:STP_12_02_01_00_RC01.tar.gz
stpmon:app:STPMON_12_02_01_00_RC01.tar.gz
tag:app:STPPRODUCTS_12_02_01_00_RC01.tar.gz
stpweb:web:STPWEB_12_02_01_00_RC01.tar.gz

script pick one line at a time and do the above operation I want when it do resync operation it find the tar ball in above resyn location and count..and each resync operation it will do the same .After that I can find the number of tar balls resync is equal to number of line in abobe file.This can be done only if I know how to implment the counter


Code:
suppose
count=0[initally]
resync operation occur
it founds one tar ball /mnt/projetcs/temp
count=0+1
count=1
again script do all it part and now doing resyc operation in
/mnt/projects/temp and found one tar ball
count=1+1
count=2

Sponsored Links
    #2  
Old 05-29-2012
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 3,289
Thanks: 27
Thanked 450 Times in 351 Posts
You might want to read the man page of the shell you are using (and which you forgot to tell us), specifically the chapter about "Arithmetic Operations" or something such.

Use


Code:
typeset -i integervar=0

to declare a variable. Use


Code:
(( integervar += 1 ))

to increment the variable. Notice that "((" and "))" HAS TO HAVE a space char after/before it, otherwise it will not work as expected. In the following the first line is correct, the second is not:


Code:
(( integervar += 1 ))  # correct
((integervar += 1))    # WRONG!

I hope this helps.

bakunin
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
File merging based on different counter loop manas_ranjan Shell Programming and Scripting 0 03-26-2012 01:21 PM
loop with a counter on a constant in bash rxc23816 Shell Programming and Scripting 1 08-26-2011 07:48 AM
S# in a for loop - concatenate $(loop counter) fight4love Shell Programming and Scripting 5 07-05-2011 11:42 PM
Using the counter of a for loop in command line parameter jeriryan87 Shell Programming and Scripting 2 06-11-2008 12:17 PM
Loop counter variable display lifespan Shell Programming and Scripting 2 03-28-2006 05:21 PM



All times are GMT -4. The time now is 04:47 AM.