1

Something has been gnawing at me for a while now and I can't seem to find a relevant answer either in man pages or using your 'Don't be evil' search engine.

My .bashrc has the following:

shopt -s histappend
HISTSIZE=100
HISTFILESIZE=0   # 200 previous value

Putting HISTFILESIZE to 0 allows me to start with a clean history slate with each new term window.

I find it practical in conjunction with using a prompt that contains \#, because when visualizing a previous command before recalling it with !n or !-p, one can just do:

$ history | more 

to see its relevant "n" value

In my case, usually the result of:

$ \history | tail -1 | awk '{print $1}'   # (I know this is an overkill, don't flame me)

equals the expanded value of # in PS1 minus 1, which is how I like it to be at all times. But then, sometimes not. At times the expanded value of # sort of "runs away". It's incremented in such a a manner that it becomes > than

$(( $(\history | tail -1 | awk '{print $1}')+1 ))

Any pointers, anyone?

  • Thanks for the edit Terdon. Was just doing that myself, when you submitted yours. – Cbhihe Jun 13 '14 at 10:11
  • Can you give us an example of when this happens? Also, what's the output of echo $HISTCONTROL? Does it only happen when you run the same command twice? Can it be with any command? Also, while this shouldn't cause any problems as such, there's no point in using the histappend option if you have your history file size set to 0. – terdon Jun 13 '14 at 11:36
  • Right on terdon ! My $HISTCONTROL is set to "ignoreboth". I should have thought about that, in conjunction with my use of \# in my prompt. I'd better use \! in PS1 in that case, because I do want "ignoreboth" on. Tx – Cbhihe Jun 13 '14 at 13:30
0

The likeliest reason for this is that you've set HISTCONTROL to a value that includes ignoredupes. Test by running

echo $HISTCONTROL

If that returns something like ignoredups, this means that duplicate commands are not saved to your history. They are however counted by PS1's \#. This means that \# will happily increment each time you run the same command twice but your history will not increase and this will lead to the discrepancy you observe.

So, either remove the ignoredupes from HISTCONTROL (this is usually set in your ~/.profile but can also be set in ~/.bashrc) or use \! instead of \# in PS1.

  • ok. question solved. solution is in my comment as a response to your initial comment Terdon. Your original comment mentioning $HISTCONTROL did it. – Cbhihe Jun 13 '14 at 15:28

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.