[comp.unix.shell] KornShell history numbers

bryan@well.sf.ca.us (Bryan Higgins) (06/24/91)

Does anyone know how the history numbers are handled from login to login?
That is, if the current command number is, say, 427, and one logs out and logs
back in, the new current command number might be something like 203, with all
the previous commands renumbered accordingly.  I've experimented with this a
little bit, and can't see any logic in the renumbering.

Actually, I'd like all the old commands renumbered starting at 1 every time I
log in.  Is there a way to achieve this?

bryan@well.sf.ca.us

bryan@well.sf.ca.us (Bryan Higgins) (06/26/91)

I wrote:


>Does anyone know how the history numbers are handled from login to login?
>That is, if the current command number is, say, 427, and one logs out and logs
>back in, the new current command number might be something like 203, with all
>the previous commands renumbered accordingly.  I've experimented with this a
>little bit, and can't see any logic in the renumbering.

>Actually, I'd like all the old commands renumbered starting at 1 every time I
>log in.  Is there a way to achieve this?

Some of you wrote and suggested I delete the history file at login, but
notice I said renumber =old= commands starting at 1, not throw away the his-
tory completely.  In other words, if my HISTSIZE is 64, I want to be at com-
mand 65 when I log in.  Turns out the shell keeps more than HISTSIZE com-
amnds in the file (though it doesn't let you get at them), so the history
number is big.  How much it deletes from the file when one logs in (it =is=
trimming it time) seems haphazard.

I've solved this with the following:

#include	<stdio.h>
#include	<ctype.h>

main()
{
	int	n;
	char	line[1024];
	char	*p;

	fwrite("\201\001", 1, 2, stdout);
	while (fgets(line, sizeof(line) - 2, stdin)) {
		for (p = line;  isspace(*p);  ++p) {
			;
		}
		n = strlen(p);
		if (n++ & 1) {
			p[n++] = '\0';
		}
		fwrite(p, 1, n, stdout);
	}
}

If the executable is called 'newhist', then

fc -l -63 -1 | newhist > tmp
mv tmp $HISTFILE

at the start of .profile will do the job.

bryan@well.sf.ca.us (Bryan Higgins) (06/26/91)

I wrote:

>fc -l -63 -1 | newhist > tmp
>mv tmp $HISTFILE

Woops; should be fc -ln.