Cleverly skipping statements from being saved to history in your shell.

I recently had to execute a statement that I did not want bash to save in its history. This led me to the bash variable HISTCONTROL.

I recently had to execute a command that I did not want the shell to save in its history.

bash

After a little searching, I finally understood what this little variable HISTCONTROL does. Definitely seen it around, never bothered with it; one of those things.

As long as it is set to either ignoreboth or ignorespace, anything starting with a space will not be saved to history.

 echo "Hello world!"

The command will still execute as normal, but that extra space makes a difference. Continue reading with an authoritative article on LinuxJournal.com from 2009.

zsh

Thanks to rzg for pointing out the zsh-equivalent: HIST_IGNORE_SPACE.

setopt HIST_IGNORE_SPACE
0

Comment via email.