Issue
When doing software development, there is often need to include confidential information in command line commands. Typical example is setting credentials for deploying the project to a server as environment variables.
How can I execute some commands, when I don't want to store them in the command history?
Nobody must be able to search them in the .bash_history
file. Is there a way how to execute Bash commands this way?
Solution
Start your command with a space and it won't be included in the history.
Be aware that this does require the environment variable $HISTCONTROL
to be set.
Check that the following command returns
ignorespace
orignoreboth
:echo $HISTCONTROL
To add the environment variable if missing, the following line can be added to the Bash profile. E.g., to file
%HOME/.bashrc
.export HISTCONTROL=ignorespace
After sourcing the profile again, space-prefixed commands will not be written to $HISTFILE
.
Answered By - u-punkt Answer Checked By - Willingham (WPSolving Volunteer)