Turn Off Bash History for the Current Session
Stop a Bash session from saving history with unset HISTFILE. The commands stay in memory until the shell exits, but nothing is saved to the file.
A session will handle sensitive commands, and you want none of it saved when you leave.
export HISTFILE=$PWD/hist
bash -i > /dev/null 2>&1 <<'EOF'
echo before
unset HISTFILE
echo after
EOF
ls hist 2> /dev/null || echo "no history file was written"
bash -i > /dev/null 2>&1 <<'EOF'
echo kept
EOF
cat histno history file was written
echo keptBash writes the in-memory history to the file named by HISTFILE when an interactive shell exits. Unsetting the variable first means there is no file to write: in the run echo before and echo after produced no history file at all, and a second session without the unset saved echo kept. The session's history is still available with the history command while it lasts. See Bash History Facilities.
It affects the current shell only, and commands from before the unset are not saved either, because writing happens at exit. It does not touch the terminal's scrollback or logs kept by sudo, auditd or a remote shell. To clear what is in memory instead, run history -c.