5

I am setting up my first MacBook. I copied by .bash_aliases file from my Linux Mint. After that, I can not open Terminal with a bash session. I just see a black screen and bash taking 100% of my CPU.

I found that the problem is HISTSIZE=-1

Why does bash fall into an infinite loop? And how do I allow unlimited history?

agarza
  • 2,274
  • First, are you certain you’re in Bash and not Zsh? By “first” MacBook, I’m assuming new or new-ish. The default shell is now Zsh. Secondly, (if I remember correctly) you can have an “unlimited” history by unsetting the value, not setting it negative. – Allan Jul 18 '23 at 16:20
  • 2
    @Allan From bash(1): "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." – nohillside Jul 18 '23 at 17:15
  • Sorry, I meant set to null which is different from unsetting. The most likely cause of the system slowness is Bash reading a super huge history file consuming system resources. The OP should try pruning old history entries – Allan Jul 18 '23 at 17:23
  • @Allan: I switched it from zsh to bash: echo $SHELL (/bin/bash). There is no old history at all. This is a new MacBook. – Eugen Konkov Jul 18 '23 at 20:18
  • So, just to confirm, you didn’t copy over any of the dot files from Mint to your Mac other than the aliases? How big/small is your history file size? – Allan Jul 18 '23 at 20:34
  • @Allan: I copied .inputrc, .profile, .bashrc, .bash_aliases. I removed all not required content from them. Also I tested that 100% CPU usage was caused only by HISTSIZE=-1 line. When I comment it out, all works as expected. When I asked the question the .bash_history file does not exists at all. As of now it is 70 bytes. Yes, only couple of commands there. – Eugen Konkov Jul 18 '23 at 20:57
  • HISTSIZE with values less than zero are applicable to Bash 4 and above. If you look at the man page on your machine (man bash) you see it makes no reference to this (v3.2), but the current Bash version (v5.2) does. You were probably using a newer Bash on Mint. If you update Bash, it should work fine. – Allan Jul 18 '23 at 21:22
  • @Allan: $ bash --version bash --version GNU bash, version 5.2.15(1)-release (x86_64-apple-darwin22.1.0) Copyright (C) 2022 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> – Eugen Konkov Jul 18 '23 at 21:42
  • 2
    In comments, you said you’re using /bin/bash which is included with macOS. That version is 3.2. What you got with echo $SHELL. If you have Bash 5.2 installed, you need to change the user shell (chsh) to the version/location where you updated it (Homebrew, I’m guessing?). – Allan Jul 18 '23 at 21:56
  • @Allan: I understand my error. /bin/bash --version GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin22) Copyright (C) 2007 Free Software Foundation, Inc. $ which bash /usr/local/bin/bash Thank you, Allan – Eugen Konkov Jul 19 '23 at 15:26

1 Answers1

5

Thanks to Allan. The problem was with an old bash version. v3.2 does not support yet HISTSIZE=-1.

So I allow my new bash echo '/usr/local/bin/bash' >> /etc/shells. (otherwise I got error: chsh: /usr/local/bin/bash: non-standard shell.

And then changed the shell to it: chsh -s /usr/local/bin/bash