UNIX csh: How do I increment a variable by one?

damunzy

recovering former mod
Retired Moderator
Joined
Oct 29, 2000
Messages
4,981
Location
NJ, USA
I have a script that changes the version number of a lot of files and instead of having to change this version manually every time I run the script I want it to automatically add one to it. This is part of what I have so far:
Code:
#!/usr/bin/csh

setenv  VERSION 4.2.4.6

VerUpdate -p . ISHOPC -i $VERSION

VerUpdate is a separate program that inserts the number set by VERSION into the file in ISHOPC.

I want the script to take that 4.2.4.6 and make it a 4.2.4.7 the next time I run it and the 4.2.4.8 the next time after that without any input from me besides running the script.
 
Okay, I have the variable increase by one but how do I get it back into the file and saved?

This is what I have so far:
Code:
#!/usr/bin/csh
setenv VAR          6
setenv VAR_PLUS_1   `expr $VAR + 1`
setenv VERSION      4.6.2.${VAR_PLUS_1}
 
Anyone???
 
In the olden days we used to use 'grep'.
Not as elegant as what you want to do but it could tide you over.

Sorry can't answer any better but I see you had the patience of 'Job' waiting for a reply so I thought I'd help as best I could.
 
Back
Top Bottom