From 8d3d0789172ab3f6580d04cd4bbafaef5e108ac7 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 4 Jul 2025 12:47:11 +0200 Subject: shell: empty HISTFILE disables history saving, just as unset one did The rationale here is that unsetting HISTFILE in /etc/profile does not "stick": if it's unset, the default one is set later (after /etc/profile is executed) by the shell. But setting (and exporting, so it is inherited by all (grand)child shells) an empty one works. function old new delta save_history 296 316 +20 Signed-off-by: Denys Vlasenko --- libbb/lineedit.c | 6 ++++-- shell/ash.c | 2 +- shell/hush.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/libbb/lineedit.c b/libbb/lineedit.c index fe0dbc5b8..43d1da35c 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -1563,7 +1563,8 @@ void FAST_FUNC save_history(line_input_t *st) { FILE *fp; - if (!st || !st->hist_file) + /* bash compat: HISTFILE="" disables history saving */ + if (!st || !st->hist_file || !state->hist_file[0]) return; if (st->cnt_history <= st->cnt_history_in_file) return; /* no new entries were added */ @@ -1617,7 +1618,8 @@ static void save_history(char *str) int fd; int len, len2; - if (!state->hist_file) + /* bash compat: HISTFILE="" disables history saving */ + if (!state->hist_file || !state->hist_file[0]) return; fd = open(state->hist_file, O_WRONLY | O_CREAT | O_APPEND, 0600); diff --git a/shell/ash.c b/shell/ash.c index 18344767a..1a85eec71 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -14540,7 +14540,7 @@ exitshell(void) /* HISTFILE: "If unset, the command history is not saved when a shell exits." */ hp = lookupvar("HISTFILE"); line_input_state->hist_file = hp; - save_history(line_input_state); /* no-op if hist_file is NULL */ + save_history(line_input_state); /* no-op if hist_file is NULL or "" */ } #endif diff --git a/shell/hush.c b/shell/hush.c index 68aca53a3..0b2bc01f5 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -2120,7 +2120,7 @@ static void hush_exit(int exitcode) /* HISTFILE: "If unset, the command history is not saved when a shell exits." */ hp = get_local_var_value("HISTFILE"); G.line_input_state->hist_file = hp; - save_history(G.line_input_state); /* no-op if hist_file is NULL */ + save_history(G.line_input_state); /* no-op if hist_file is NULL or "" */ } #endif -- cgit v1.2.3-55-g6feb