113 reputation
5
bio website
location
age
visits member for 2 years, 10 months
seen Mar 25 at 6:32

Apr
14
awarded  Popular Question
Jul
20
comment How to stop Bash appending history
@ChrisPage yes I know that but it does not save it the way I would like, hence using the logout script to achieve the result I desired. Your original question was why it makes a difference to write after appending and the answer is that appending removes duplicates in the current history (combined history file and session history) which you then write to the history file. Bash's default save still saves duplicates to the history file because it only ensures that there are no duplicates in the session history not the current history.
Jul
20
comment How to stop Bash appending history
@ChrisPage Are you saying bash runs history -w after running the .bash_logout script? If so I did not know this, I assumed that nothing would be done except what is in the logout script.
Jun
10
comment How to stop Bash appending history
@ChrisPage by running history -a really what it does is the same as the default save that Bash does however this is not why we use it here. We use it because it removes all duplicates in the current history so that current history is now exactly what we want the history to look like. we then use history -w to write the current history to the history file. Hope that all made sense. I know by looking at it is seems silly to use history -a when you are going to overwrite it again with history -w but the key is history -a changes the current history.
Jun
10
comment How to stop Bash appending history
@ChrisPage when you use erasedups it stops you having duplicates in the session history only. If for example you had the command ls in the history file and you used it in this session current history would only show one entry for the command ls. However by default Bash appends session history to the history file both of which contain the command ls so next time you log in there are 2 ls commands listed. If you use it again there will be 3 next time you log in.
Jun
10
comment How to stop Bash appending history
@ChrisPage It's hard to explain in the limited text here but basically there are three histories. session history - everything newly entered in the session, history file - past history of everything before login and current history - what you see when you list the history (combination of the history file and session history).
Jun
10
accepted How to stop Bash appending history
Jun
10
awarded  Scholar
Nov
23
awarded  Tumbleweed
Sep
15
awarded  Student
Sep
15
awarded  Editor
Sep
15
comment How to stop Bash appending history
@ztank1013 thanks that lead me in the right direction, I have now added the solution.
Sep
15
revised How to stop Bash appending history
Added the solution I found
Sep
15
comment How to stop Bash appending history
Ah didn't know of it's existence, cheers.
Sep
15
asked How to stop Bash appending history