[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::digital_unix

Title:DIGITAL UNIX(FORMERLY KNOWN AS DEC OSF/1)
Notice:Welcome to the Digital UNIX Conference
Moderator:SMURF::DENHAM
Created:Thu Mar 16 1995
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:10068
Total number of notes:35879

9141.0. "How to implement a shell script counter" by SANITY::LEMONS (And we thank you for your support.) Wed Mar 12 1997 12:46

    Hi
    
    What's the correct way to increment a counter in a DU shell script?
    
    I've tried
    
    i = i + 1
    i = $i + 1
    @i = $i + 1
    
    with and without parentheses, and get an error for all of them.  I
    looked in the 'Command and Shell User's Guide', and didn't see an
    examples for doing this.
    
    Is there a good book on writing shell scripts for Digital UNIX?  The
    section in 'Command and Shell User's Guide' is pretty weak.
    
    Thanks!
    tl
T.RTitleUserPersonal
Name
DateLines
9141.1NETRIX::"[email protected]"Chyan,Chia-Jen LiuWed Mar 12 1997 13:2115
The following will work for both ksh and sh.
You can also do a manpage on expr.
 
$ count=1
$ c=`expr $count + 1 `
$ echo "New count is $c"
New count is 2



Regards,
Chia-Jen Liu Chyan
CSC Atlanta
[Posted by WWW Notes gateway]
9141.2csh exampleNETRIX::"[email protected]"leon straussWed Mar 12 1997 16:517
Fwiw, this csh example works for me ...

	set count=0
	@ count = $count + 1

	leon
[Posted by WWW Notes gateway]
9141.3++VAXCPU::michaudJeff Michaud - ObjectBrokerWed Mar 12 1997 20:308
> Fwiw, this csh example works for me ...
> 	set count=0
> 	@ count = $count + 1

	And don't forget this is the "C" shell, so when in Rome ...

		set count=0
		@ count++
9141.4SANITY::LEMONSAnd we thank you for your support.Wed Mar 12 1997 21:503
    Neat-o!  Thanks, all, for the fast response!
    
    tl