History is only enabled for interactive shells, not scripts. So in a script, history -c
won't do much good. If you just want to empty your user's bash history during boot, as /tmp
is emptied during boot, just truncate or delete ~/.bash_history
.
echo "cleaning the history"
> /home/yourusername/.bash_history
This uses shell redirection without a command. It makes the shell just open the file for writing (truncating it if it already exists), then close it without writing anything to it (since there's no command to write anything to it).
On a side note, don't use absolute paths to commands in scripts. E.g. use echo
, not /bin/echo
.
update: Or if you don't want to save bash history at all, you could put something like HISTFILE=/dev/null
in your ~/.bashrc
.
bashrc
)? If so, please post the whole script. If not, why did you write it inside a function instead of a plain/bin/echo "cleaning the history"; history -c
. Also I think you're missing a semicolon in the version posted here.echo
and thehistory
command. Also if you do that from within a script you do it from the local scope of the script. Very much the same if you change a variable within a script it is not changed outside (in the terminal you ran the script in).