File Version Numbering
Frequently I've wanted to have multiple copies of a
file as it went
through various stages of rewriting and reworking. Havng
used a DEC
VAX at various points in my career, I liked the version
which VMS provides.
To address this I wrote a program called vedit (Listing 1).
vedit is a shell program which implements version numbering
a similar scheme to VMS. For each file, vedit checks
to see if there is a file in the current directory which
has a version
number. Version numbers are added to filenames by including
and a number.
For example, the file "demo" does not use
while "demo;2" does. The number 2 indicates
that this is the
second version of the file "demo". The Bourne
in Listing 1 is simple enough, and is easy to use and
However, there are some issues which should be mentioned
seimcolon is a special character to the Bourne and Korn
is used as a command separator to allow the user to
commands on the same line. For example, you can write
chare w1 Mar 23 21:40
Sat Mar 26 14:39:35 EST 1994
or you can use the semicolon and write it as
$ who; date; pwd
chare w1 Mar 23 21:40
Sat Mar 26 14:40:52 EST 1994
Consequently, the use of the semicolon in the file name
requires some special handling. To access a file under
without using the vedit command, you must use the backslash
to "escape" the meaning of the semicolon to
the shell, as,
$ cat demo\;2
To discuss the operation of the shell script in Listing 1,
I have numbered it using the UNIX pr command. Line
the files that contain a semicolon, and replaces all
of the text in
the file name with blanks. The end result is a list
of numbers in
reverse sorted order. The result of this list is the
last or highest
number in the list. If the file is new, then the first
used is 1.
Lines 36 to 58 determine what version number is to be
used, and set
some variables which will be used later in the script.
Lines 63 to
75 copy the original file to the new filenme for editing.
copy fail, the user is informed with the error message.
The most likely
causes of such a failure would be the permissions on
involved, or an inability to read the source file.
The file is loaded for editing in line 79; upon exit,
the script verifies
that editing did in fact occur. The diff command in
compares the two files. If no changes were made, then
to line 117, where the user is told that no changes
were made and
the newly created file is removed.
If changes were made, then the lines and bytes in the
file are counted
by the wc command in line 104, and the information on
edit is recorded in an edit history file, the name of
of the filename plus a .INDEX entension. The information
the index file includes the file name and version, the
name of the
person who edited it, the date and time, and the lines
and byte count
of the new file.
Line 116 connects the newly created file with the name
the user. This way, the user doesn't need to remember
version of the file, unless he or she chooses to return
to an earlier
Source Code Control or Revision Control systems can
be used to accomplish
a similar goal, but are not for the average user. System
can use vedit to edit and manipulate system configuration
files and keep a log of those edits.
About the Author
Chris Hare is Ottawa Technical Services Manager for
Choreo Systems, Inc.
He has worked in the UNIX environment since 1986 and
in 1988 became one of
the first SCO authorized instructors in Canada. He teaches
system administration, and programming classes. His
current focus is on
networking, Perl, and X. Chris can be reached at email@example.com,
firstname.lastname@example.org, which is his home.