Bash Command History – Why Not Set ‘histappend’ in Bash?

bashcommand history

After finding out what this shopt -s histappend means, it seems a very sane setting, and I'm surprised that it isn't default. Why would anyone want to wipe their history on each shell exit?

Best Answer

Well, when histappend is not set, this does not mean that the history is wiped on each shell exit. Without histappend bash reads the histfile on startup into memory - during operation new entries are added - and on shell exit the last HISTSIZE lines are written to the history file without appending, i.e. replacing the previous content.

For example, if the histfile contains 400 entries, during bash runtime 10 new entries are added - histsize is set to 500, then the new histfile contains 410 entries.

This behavior is only problematic if you use more bash instances in parallel. In that case, the history file only contains the contents of the last exiting shell.

Independent of this: There are some people who want to wipe their history on shell exit because of privacy reasons.