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?
2 Answers
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
histappendhave any relevance to whetherroot's history reaches a disk? Again, it only affects what is written, not if.underscore_d– underscore_d2015-11-16 22:54:57 +00:00Commented Nov 16, 2015 at 22:54 -
10does anyone run less than 2 bash instances?
histappendas well asHISTCONTROL=ignoredups:erasedups:ignorespaceseems like a good default for most people.dashesy– dashesy2016-05-25 22:22:39 +00:00Commented May 25, 2016 at 22:22 -
1Is
histappendeffective meaningless if I haveHISTFILESIZE=andHISTSIZE=for infinite history?Marc.2377– Marc.23772019-06-17 01:32:41 +00:00Commented Jun 17, 2019 at 1:32 -
2@Marc.2377 No, without
histappendnew 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 ifHISTSIZE=has the same effect as a negativeHISTSIZE.maxschlepzig– maxschlepzig2019-06-17 18:26:13 +00:00Commented Jun 17, 2019 at 18:26 -
3@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– msb2019-11-20 19:14:05 +00:00Commented Nov 20, 2019 at 19:14
For historical compatibility, I guess. The histappend option didn't exist until bash 2.0.
-
1Was history overwritten each time?tshepang– tshepang2011-01-27 04:59:28 +00:00Commented Jan 27, 2011 at 4:59
-
4@Tshepang: Yes, same as now if you don't use
histappend.Gilles 'SO- stop being evil'– Gilles 'SO- stop being evil'2011-01-27 08:22:42 +00:00Commented Jan 27, 2011 at 8:22 -
1it should be the default now but it is notdashesy– dashesy2016-05-25 22:23:23 +00:00Commented May 25, 2016 at 22:23
bash'pure' or a distro-supplied.bashrc. for the former, @Gilles is probably correct. in the latter sense,-s histappendis default on, e.g., Debian, since 2008: bugs.debian.org/cgi-bin/bugreport.cgi?bug=452459