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


damunzy
Dec 26, 2002, 05:58 PM
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:

#!/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.

damunzy
Dec 26, 2002, 08:40 PM
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:

#!/usr/bin/csh
setenv VAR 6
setenv VAR_PLUS_1 `expr $VAR + 1`
setenv VERSION 4.6.2.${VAR_PLUS_1}

damunzy
Jan 20, 2003, 11:38 AM
Anyone???

Cartouche Bee
Jan 20, 2003, 12:27 PM
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.