Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

zsh: corrupt history file



Research on Google suggests the 'corrupt history file' problem is rare. In my experience, it is not; I get these _all_ _the_ _time_.

I've identified one source of corruption: $HISTFILE. Korn shell *uses* but does not *require* this variable be set. If unset, it uses ~/.sh_history as a default. `zsh` *requires* this variable be set, or there is no persistent history feature. However, once set, if the user enters `ksh` (shelling out from an editor, for instance; or starting another shell to run a few experiments to compare behavior and increase understanding, or try commands to ensure a solution is portable for a script), then Korn shell does what it's told and appends its commands to the .zsh_history file. And a `corrupt history file` ensues.

This does not happen with bash; although bash uses $HISTFILE it seems to use a similar history format to zsh. ksh does some unusual encoding.

A solution to this is to add to .kshrc a `HISTFILE=$HOME/.sh_history` and to .zshrc a `HISTFILE=$HOME/.zsh_history`, so that if invoking different shells they do not corrupt each other's history files.

This issue should be noted in the man page, either with $HISTFILE's explanation, or in the BUGS section.


When corruption *does* occur, it is compounded by zsh's behavior: all sessions sitting at prompts, will ignore their next command and display the corruption error message. Then they starts working normally again, history and all. It sucks that I lost the past, but having every window drop one command gets super frustrating; essentially, this error isn't just effecting the history, it's effecting the future.

Even if the past has to be lost, it would be much less frustrating to have zsh *execute the inputted command*, then display the error before prompting for the next command. For me, this is the real irritation, usually more than losing any history.

Perette Barella



Messages sorted by: Reverse Date, Date, Thread, Author