Contents

Shell quick tips: Bash incognito mode

Contents

Shell history is essential but sometimes undesired and has to be disabled. This is often the case when working with API keys, passwords or any type of credentials. I often find myself using API keys like that when working on a new script or doing some simple API tests with curl.

Bash, allows disabling history using:

set +o history

but this is not very convenient as the history is disabled in the running session as well so, jumping back is no longer possible.

There are some other variables to customise history configuration, specifically:

  • HISTFILE - name of the file to which history is saved
  • HISTFILESIZE - The maximum number of lines contained in the history file
  • HISTIGNORE - A colon-separated list of patterns used to decide which command lines should be saved on the history list
  • HISTSIZE - Number of commands to remember in the command history
  • HISTTIMEFORMAT - Specify timestamp format

The only useful variables on that list that can be used to temporarily disable history are HISTFILE and HISTIGNORE. I like to use HISTFILE for that purpose and just set it to an empty string:

HISTFILE= bash

This creates a new shell session which maintains a ‘runtime’ history so, it’s possible to navigate around but nothing is saved to .bash_history (or whatever other file you’re using for that purpose).

I like to have a convenient alias for that purpose:

alias incognito='HISTFILE= $SHELL'