Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!well!bryan From: bryan@well.sf.ca.us (Bryan Higgins) Newsgroups: comp.unix.shell Subject: Re: KornShell history numbers Message-ID: <25677@well.sf.ca.us> Date: 26 Jun 91 02:48:18 GMT References: <25628@well.sf.ca.us> Distribution: comp Lines: 50 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 #include 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.