1

When I start bash or any other shell, it has no history. Do you have any idea what I can do about it? I'm trying to use the upwards arrow and it has no effect if I start a new shell with OpenBSD or Ubuntu xenial.

I tried every configuration that was mentioned, I set $HISTFILE in my .profile , I logged out and logged in again and I use two different operating systems.

This is exactly my configuration and how I log in and have no history per deafult:

developer@1604:~$ ssh 127.0.1.2 -l root -p 2223
[email protected]'s password: 
Last login: Sat Aug 19 01:34:14 2017
OpenBSD 6.1 (GENERIC) #19: Sat Apr  1 13:42:46 MDT 2017

Welcome to OpenBSD: The proactively secure Unix-like operating system.

Please use the sendbug(1) utility to report bugs in the system.
Before reporting a bug, please try to reproduce it with the latest
version of the code.  With bug reports, please try to ensure that
enough information to reproduce the problem is enclosed, and if a
known fix for it exists, include that as well.

# history                                                               
ksh: fc: no history (yet)
# more .profile                                                                
# $OpenBSD: dot.profile,v 1.9 2010/12/13 12:54:31 millert Exp $
#
# sh/ksh initialization

PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/sbin:/usr/local/bin
export PATH
: ${HOME='/root'}
export HOME
umask 022

case "$-" in
*i*)    # interactive shell
        if [ -x /usr/bin/tset ]; then
                if [ X"$XTERM_VERSION" = X"" ]; then
                        eval `/usr/bin/tset -sQ '-munknown:?vt220' $TERM`
                else
                        eval `/usr/bin/tset -IsQ '-munknown:?vt220' $TERM`
                fi
        fi
        ;;
esac
# 
Niklas Rosencrantz
  • 4,112
  • 6
  • 36
  • 58
  • 2
    If you are still having problems getting command line history to work for the OpenBSD `ksh` shell, you should add your shell config files to the question. – Kusalananda Aug 25 '17 at 20:58
  • 1
    [Previously](https://unix.stackexchange.com/q/386319/117549) – Jeff Schaller Aug 25 '17 at 21:03
  • Does up-arrow do *nothing* or does it give `^[[A`? – Jeff Schaller Aug 25 '17 at 21:04
  • Yes, just wanted to see if we should close this Q in favor of the previous, or focus this one on bash, perhaps? – Jeff Schaller Aug 25 '17 at 21:05
  • @JeffSchaller Well, this is slightly broader. History doesn't work in _any_ shell, he says. – Kusalananda Aug 25 '17 at 21:07
  • 2
    I'm not convinced it's not readline/ terminal interaction vs lack of history. Dj, can you run "history" and see previous commands? – Jeff Schaller Aug 25 '17 at 21:11
  • 2
    Is you home directory writable by you? What gives `ls -ld ~; id -un` ? – xhienne Aug 25 '17 at 21:24
  • @xhienne `drwxr-xr-x 120 developer developer 12288 aug 25 22:33 /home/developer 1000` – Niklas Rosencrantz Aug 26 '17 at 02:33
  • @JeffSchaller If I run "history" it says "no history yet" with Ubuntu and with OpenBSD too. – Niklas Rosencrantz Aug 26 '17 at 02:34
  • @DjDac This is with `pdksh`? You _have_ to show your configuration and _exactly_ what it is you're doing. We can't see what shell you're doing what in. – Kusalananda Aug 26 '17 at 06:49
  • @Kusalananda It's a clean OpenBSD VM 6.1 VM Image in virtual box and I just log in and press the upwards arrow and get no history. – Niklas Rosencrantz Aug 26 '17 at 07:24
  • @DjDac Yes, well, none of us are _real_ wizards (even though we may have beards), so we can't see your configuration without you showing it. Your setup is identical to mine (OpenBSD 6.1 in VirtualBox) so I see no reason that my suggestion (to your prev. question) would not work, other than a misconfiguration of the shell initialization files. It's a misspelling of a variable, filename or other, or a compatibility issue between shells (e.g. sharing init files and messing it up, or sharing history files). – Kusalananda Aug 26 '17 at 07:32
  • you explicitly *DO NOT* have HISTFILE set in your .profile! – Jeff Schaller Aug 27 '17 at 17:35
  • are you setting HISTFILE in your developer account, and not in the root account?? – Jeff Schaller Aug 27 '17 at 17:35

2 Answers2

3

Your ~./profile does not enable saving the history at the moment (there is no setting of HISTFILE anywhere in there).

For the OpenBSD ksh shell in the base system:

Edit your ~/.profile file and add the following line:

export ENV="$HOME/.kshrc"

Then edit ~/.kshrc and add the following lines:

set -o emacs
HISTFILE="$HOME/.ksh_history"

This should be enough. The set -o emacs is to make the arrow keys work as you expect them to (you had issues with this I believe).

It is also enough to just set HISTFILE="$HOME/.ksh_history" directly in .profile if you wish to avoid using a separate file for interactive shells.

You may also specify the number of history entries that you'd like to save with, e.g.,

HISTSIZE=5000

The default value of HISTSIZE is 500.

This is more or less what I wrote in my previous answer too.


There is currently (late Aug 2017) a flurry of CVS commits to the OpenBSD ksh implementation, to implement various history-related features such as HISTCONTROL, ignoredups and ignorespace (as available in e.g. bash).

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
2

Append these lines to your ~/.bashrc

set -o history
HISTFILE=$HOME/.bash_history
HISTFILESIZE=500
HISTSIZE=500
shopt -s histappend

Then enter the command source .bashrc, and then enter a few random commands. See if now you have a history (enter history at the command line, or use the up-arrow).

gracious1
  • 629
  • 4
  • 12
  • The OP has tagged this Question amongst other things with `ubuntu` and `openbsd`. So I have `ubuntu` and a working bash history, but I don't have in my `~/.bashrc` the 1st line and the 2nd line differs from my. So is this really related to `ubuntu`? – John Goofy Aug 26 '17 at 13:46
  • 1
    @JohnGoofy The first two lines _shouldn't_ be necessary (regardless of OS) as the `history` option is turned on by default in interactive shells, and the `HISTFILE` variable is likewise set by default. The reason he has them there is to make sure they _actually_ are active in case some system configuration file (e.g. `/etc/profile`) disables them. – Kusalananda Aug 26 '17 at 16:20
  • @Kusalananda Yes, exactly. Also, I was hoping OP would follow instructions, "See now if you have a history", for if it didn't work, there are other things to try. But so far, OP is silent. – gracious1 Aug 26 '17 at 16:55
  • I don't get a history no matter what I do. I don't understand why. – Niklas Rosencrantz Aug 27 '17 at 13:25