Not directly the requested answer, but maybe the root-cause of the question:
You can also prevent commands from even getting into the history, by prefixing them with a space character:
# This command will be in the history
echo Hello world
# This will not
echo Hello world