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?

  • aside from the misunderstanding of what this option does - corrected by @maxscchlepzig - "default" has at least two sources: bash 'pure' or a distro-supplied .bashrc. for the former, @Gilles is probably correct. in the latter sense, -s histappend is default on, e.g., Debian, since 2008: bugs.debian.org/cgi-bin/bugreport.cgi?bug=452459 – underscore_d Nov 16 '15 at 23:00
  • 3
    Well, unix isn't exactly famous for sane defaults? I've come to expect the most unfriendly defaults by default :P (minor exaggerated) – olejorgenb Oct 20 '16 at 8:27

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.

  • 1
    +1 for "does not mean that the history is wiped on each shell exit". This is explained perfectly well elsewhere - but perhaps not succinctly enough to reach some readers, especially in the context of the option's name (OK, I might have been one of those readers for awhile). @Mei, how does either permutation of histappend have any relevance to whether root's history reaches a disk? Again, it only affects what is written, not if. – underscore_d Nov 16 '15 at 22:54
  • 7
    does anyone run less than 2 bash instances? histappend as well as HISTCONTROL=ignoredups:erasedups:ignorespace seems like a good default for most people. – dashesy May 25 '16 at 22:22
  • 1
    Is histappend effective meaningless if I have HISTFILESIZE= and HISTSIZE= for infinite history? – Marc.2377 Jun 17 '19 at 1:32
  • 1
    @Marc.2377 No, without histappend new history from concurrently running shells would then be lost and only the entries of the last exiting shell would be saved. Btw, I don't know if HISTSIZE= has the same effect as a negative HISTSIZE. – maxschlepzig Jun 17 '19 at 18:26
  • 1
    @dashesy I personally don't like to ignore/erase duplicate entries. I have HISTTIMEFORMAT enabled, and I like to be able to go back and see when I issued a command... and if I issued it multiple times, I like to know when each one was issued. It's a personal preference, to which their own. ;) – msb Nov 20 '19 at 19:14

For historical compatibility, I guess. The histappend option didn't exist until bash 2.0.

  • 1
    Was history overwritten each time? – tshepang Jan 27 '11 at 4:59
  • 4
    @Tshepang: Yes, same as now if you don't use histappend. – Gilles 'SO- stop being evil' Jan 27 '11 at 8:22
  • it should be the default now but it is not – dashesy May 25 '16 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.