@David Dai tiene razón sobre este hilo de ayuda bash -.
Aquí está el código relevante bash
en C.
if (history_lines_this_session <= where_history () || force_append_history)
{
result = append_history (history_lines_this_session, hf);
history_lines_in_file += history_lines_this_session;
}
else
{
result = write_history (hf);
history_lines_in_file = history_lines_this_session;
}
shopt -s histappend
establece force_append_history
en no -cero(true
).
history_lines_this_session
es el número de comandos que escribió en esta sesión interactiva bash
. Cuando inicia bash por primera vez, es 0. Aumenta en 1 cada vez que ingresa un comando que se guarda en el historial.
where_history()
es un índice en la lista de historial de memoria -, que comienza en el índice 0. Apunta al siguiente índice para escribir el historial. Por ejemplo, cuando tenga 0 historial, será el índice 0. Cuando tenga 6 líneas de historial, será el índice 6.
Cuando inicia por primera vez bash
y tiene historial en su HISTFILE
, where_history()
aumenta pero se limita a <= HISTSIZE
. Entonces where_history()
tiene un valor máximo de HISTSIZE
.
Después de leer HISTFILE
, where_history()
aumentará pero history_lines_this_session
seguirá siendo 0. Cuando ingreseHISTSIZE + 1
el número de comandos, history_lines_this_session == HISTSIZE + 1
ywhere_history() == HISTSIZE
(porque está limitado en el máximo ). En este punto, (history_lines_this_session <= where_history()) == false
se sobrescribirá el historial si histappend
está desactivado.
Puedes probar esto en tu bash
tú mismo. Si histappend
está desactivado, una vez que ejecute HISTSIZE + 1
el número de comandos, history_lines_this_session
excederá where_history()
en 1 y HISTFILE
se sobrescribirá. Debe asegurarse de que otros comandos no interfieran con su historial para que la prueba funcione, aunque (sucede en macOS ). Use los siguientes comandos para desactivar los comandos que pueden alterar el historial:
trap - EXIT
PROMPT_COMMAND=
SHELL_SESSION_HISTORY=0 # for macOS only