For some reason, I cant set HISTSIZE smaller than 1

$ export HISTSIZE="2"; echo $HISTSIZE
$ export HISTSIZE="1"; echo $HISTSIZE
$ export HISTSIZE="0"; echo $HISTSIZE 
$ export HISTSIZE="-1"; echo $HISTSIZE 

Interestingly, setting this to a non-numeric value also results in 1:

$ export HISTSIZE="test"; echo $HISTSIZE

It seems some kind of validation is being performed silently. Any idea where I should be looking?

I want to set HISTSIZE to -1 so that I can get infinite history.

I am currently using zsh 5.1.1 with oh-my-zsh

Worth pointing out that HISTFILESIZE does not have this issue:

  • HISTFILESIZE isn't a zsh parameter (see man zshparams)... – Stephen Kitt Jun 1 '16 at 15:41
  • If you want to have virtually unlimited history in zsh, just set HISTSIZE to a very large number. For example HISTSIZE= 2147483647 (2^31-1), which is sufficiently large to add one command every second for the next 68 years. The maximum may depend on the hardware, on my machine it is HISTSIZE=9223372036854775807 (2^63-1), which is sufficient for 292 billion years at the same rate. Note, that you also need to set SAVEHIST in order to actually have the history written to the history file. – Adaephon Jun 1 '16 at 15:57

This is controlled by histsizesetfn() in zsh's Src/params.c:

histsizesetfn(UNUSED(Param pm), zlong v)
    if ((histsiz = v) < 1)
        histsiz = 1;

so the value of HISTSIZE can never been set to a value less than 1.

  • Well this seems silly. Why would they limit this if negative values are allowed? – Michael Aquilina Jun 1 '16 at 15:38
  • What makes you think negative values are allowed? – Stephen Kitt Jun 1 '16 at 15:41
  • from man bash - "HISTSIZE: The number of commands to remember in the command history (see HISTORY below). If the value is 0, commands are not saved in the history list. Numeric values less than zero result in every command being saved on the history list (there is no limit). The shell sets the default value to 500 after reading any startup files." – Michael Aquilina Jun 1 '16 at 16:35
  • 2
    You're running Zsh though, so bash's documentation doesn't apply... See man zshparam for Zsh. – Stephen Kitt Jun 1 '16 at 16:58
  • you're right. I wrongly assumed that HISTSIZE would be the same for zsh and bash because of their similarities :/ – Michael Aquilina Jun 2 '16 at 14:26

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.