How can I access the history buffer in sh? (not in Bash)
unless it is explicitly set, there is no default shell history. to verify if you have it or not, the command
env|grep -i hist can be executed and if you see variables like
histfile etc. (may be capitalized) it means that your shell history is enabled, and you should see where the history file is located. To clear, you can do any decent method, other than deleting the file
Not all shells support history.
dash has limited history support through the
fc command if compiled with libedit support, but does not support it otherwise.
dash is not capable of saving a history file.
Often, if a shell doesn't support the up arrow key, you can assume that it won't save a history file either. This isn't a hard-and-fast rule, but it's true in every case I've come across.
Some other shells (
bash notably, but others too) use readline, which generally saves history under your home directory as a
~/.*_history file, with
* being replaced with the name of the program. Python 3 uses readline for example, and stores its history in
Depending on the shell, the save location may or may not be configurable.
zsh use the
HISTFILE (all caps) variable. If your shell is configured correctly this should not be an environment variable, so if you see it in
env you have made a mistake (but it should still show in the output of
printf %s\\n "$HISTFILE").
If a program doesn't support history (for example,
ed, shell scripts using
read, or older versions of
mysql), there is a cross-platform application called
rlwrap which will use readline to give it bash-like tab completion, arrow key handling, and history.