Yes, ksh93
writes its command line history to file as you go, while bash
writes it when the shell exits. Digging though some source code, it seems that the in-memory history buffer is 4k (HIST_BSIZE
in the code), but I'm not able to figure out whether it flushes this when it's full or after a certain number of commands (whan may HIST_MARKSZ
be doing in this code?).
And yes, many interactive sessions share history if they use the same HISTFILE
setting. This is documented (my emphasis):
Command Re-entry.
The text of the last
HISTSIZE
(default 512) commands entered from a terminal device is saved in a history file. The file$HOME/.sh_history
is used if theHISTFILE
variable is not set or if the file it names is not writable. A shell can access the commands of all interactive shells which use the same namedHISTFILE
.
The history file will be kept to the size specified in HISTSIZE
but it will not be truncated periodically as you experience. What's happening for you is, I think, that since you use tty
to set a unique HISTFILE
for each interactive shell session, exiting and restarting interactive sessions may or may not pick up the "correct" history file depending on what TTY the shell is connected to.
If a new TTY (never used with a session before) is allocated for a shell session, it's history file will naturally be empty.