Terminal assigns each terminal session a unique identifier and communicates it via the TERM_SESSION_ID environment variable so that programs running in a terminal can save/restore application-specific state when quitting and restarting Terminal with Resume enabled.
A new folder (~/.bash_sessions/) is used to store HISTFILE's and .session files that are unique to sessions.
During shell startup the session file is executed. Old files are periodically deleted.
The default behavior arranges to save and restore the bash command history independently for each restored terminal session. It also merges commands into the global history for new sessions.
You may disable this behavior and share a single history by setting
export SHELL_SESSION_HISTORY=0
If HISTTIMEFORMAT is defined, per-session history is disabled by default (read more in /private/etc/bashrc_Apple_Terminal)
The save/restore mechanism is disabled if the following file exists:
~/.bash_sessions_disable
Apple already changed some behavior since El Capitan release, so it is better to go read more about this here less /private/etc/bashrc_Apple_Terminal
Hi Nelson, welcome to Super User. Quick check- ere those spaces inserted by you? – bertieb – 2015-08-04T09:20:20.880
yes they were, i'll remove them and report back. – None – 2015-08-04T09:20:49.827
@bertieb, I've removed the spaces and now $HISTFILESIZE is properly echo'd. However, history remains unsaved and $HISTFILE prints out that odd temp history file (which I'm assuming stores history for just that session). – None – 2015-08-04T09:22:57.607
Are you trying to change
$HISTFILE
, out of interest? I don't have a.bashrc
on OSX andecho $HISTFILE
reports the place I would expect- does commenting out the lines in question have any effect? – bertieb – 2015-08-04T09:42:14.057Where are you sourcing
.bashrc
? On OS X, you normally have a login shell. – fd0 – 2015-08-04T10:08:35.997@bertieb, I am not trying to change the histfile. commenting out the lines from .bashrc does not change anything in terms of output. $HISTFILESIZE and $HISTSIZE still output 500 because I believe that is the mac default. – None – 2015-08-04T19:12:36.950
@fd0, I'm not sure what your question means, could you clarify? What's the relationship between .bashrc and a login shell? – None – 2015-08-04T19:13:52.340
1Always quote pathname variable expansions:
HISTFILE="$HOME/.bash_history”
. Without the quotes, your version will be invalid if the path to your home directory contains spaces (or possibly other special characters). – Chris Page – 2015-12-30T12:48:37.587I was experiencing this same problem because my
.bash_profile
was invoking anosascript
to quit the terminal process after the last visible window/tab closed. Somehow that script was preventing the history from being stored in my history file when the terminal exited. – axiopisty – 2019-10-16T18:14:45.693