How to clean the Almquist Shell history?

Hi,I am new to FreeBSD.Recently I want to clean the command history of the default Almquist shell.I read the manual page for sh,but found no related description.Then I deleted the .sh_history file,but it is futile.Does anyone know how to properly clean it?
I am sorry if this question sounds very dumb.
 
I am sorry if this question sounds very dumb.
Not dumb, I can't figure it out either. The 'problem' with deleting the .sh_history file is that it gets rewritten when you exit the shell. So it'll just reappear with the same content it had before.

The only way to really delete it seems to be not starting /bin/sh. One way would be to chsh -s /bin/tcsh (change your user's shell to tcsh(1)). Log off and back in again (so tcsh(1) is now your active shell). Then delete .sh_history. After that you can change your shell back to sh(1); chsh -s /bin/sh.

Or login as root and delete the user's .sh_history (make sure it's not logged in or else it'll get recreated again when you exit that session).

Cumbersome, but it'll work.
 
Code:
$ HISTSIZE=0
$ rm ~/.sh_history
$ exit
% ls ~/.sh_history
ls: /home/???/.sh_history: No such file or directory
That way all the inner instances of sh(1) won't have history indeed, but the outer ones will restore the file (or maybe a part of it, if there were new history entries) nonetheless.

Unfortunately, there is no simple solution for now (UPD: if you don't want to log out). You either have to set HISTSIZE=0 all the way up, or do something like mkdir ~/.sh_history to outplay this.
 
See Thread 94037 – How do I delete the shell history? The HISTFILE variable is documented in sh(1) and can be found by looking for the word history.​
Bash:
HISTFILE=''
Setting HISTSIZE to zero does the job, too, yet also affects the volatile command history (cf. fc ‑l), which you may find inconvenient.​
 
Not dumb, I can't figure it out either. The 'problem' with deleting the .sh_history file is that it gets rewritten when you exit the shell. So it'll just reappear with the same content it had before.

The only way to really delete it seems to be not starting /bin/sh. One way would be to chsh -s /bin/tcsh (change your user's shell to tcsh(1)). Log off and back in again (so tcsh(1) is now your active shell). Then delete .sh_history. After that you can change your shell back to sh(1); chsh -s /bin/sh.

Or login as root and delete the user's .sh_history (make sure it's not logged in or else it'll get recreated again when you exit that session).

Cumbersome, but it'll work.
Is there a way to override the buffer of command history while using ash?If so then I believe deleting .sh_history plus overriding the buffer might work.
 
If you add HISTSIZE=0 to ~/.shrc, .sh_history will not be created.
Is the environment variable ENV set?
It surely won't in that shell, and even in all the subshells, if the variable was exported. But that doesn't mean the HISTFILE won't be recreated by the instance which was opened before HISTFILE='' was added to ~/.shrc (or ~/.profile, or /etc/profile), and which will be closed after the current shell was closed.

As an example, I'm currently logged in through ttyv0, from which I've interactively started my graphical environment without using exec. In this case, the only way I could finally remove/truncate HISTFILE is to set HISTFILE='' in the login shell, which would require me at least to shut down my window manager.
 
Tomolok said:
Is there a way to override the buffer of command history while using ash?If so then I believe deleting .sh_history plus overriding the buffer might work.
Yes, there is, but as was mentioned, it will only work if you don't have other shells opened at the same time.
 
Back
Top