My Bash history is remembered when I connect to my Mac via SSH, use iTerm2 or launch bash
in the built-in Terminal app (every command I typed in bash
is saved) but is not when I just use the built-in Terminal app. I already tried resetting the profiles in Terminal. I also checked ownership and permissions of .bash_history
. Later I also tried to delete this file. This answer didn't help either. My default shell definitely is bash
.
Bash history is not remembered in Terminal
bashsshterminal
Related Question
- How to switch off sharing of history between iTerm2 tabs when setopt command not found
- Save Bash shell history also when closing Terminal tab
- MacOS – Reset terminal environment to start up state, not losing print of history
- Scrolling doesn’t work in Terminal for commands like less
- Bash history not initially remembered with iterm2
- “bash” command runs scripts in version 3.2, not 4.4
- MacOS – Unexpected -bash command not found error when starting new mac terminal window
Best Answer
Begin isolating the source of the problem by removing any customizations of Bash’s history. For example, any code that sets shell variables that begin with
HIST
, or usesset -o
to set either thehistory
orhistexpand
shell options.The per-session command history code in
/etc/bashrc_Apple_Terminal
attempts to maintain compatibility with Bash’s history variables, and tries to detect when the user is probably doing something it can’t be compatible with and disables the mechanism in that case (because the user is doing something arbitrary, like loading, saving or modifying the history). However, if you have scripts that run thehistory
command, that code has no way of knowing in advance; you’ll need to either update your code to maintain compatibility with the new per-session command history, or disable the per-session history by settingSHELL_SESSION_HISTORY=0
as described in the documentation in/etc/bashrc_Apple_Terminal
.If you’re not customizing
HISTFILE
,HISTTIMEFORMAT
or thehistappend
shell option, another thing to check is if your shell startup script(s) modify eitherPROMPT_COMMAND
variable or theEXIT
trap without concatenating the previous value to avoid wiping it out.See the comments in
/etc/bashrc_Apple_Terminal
for a description of how the mechanism works and how to customize or disable it.