4

I cannot find any indication that sh supports persistent history. So I am trying to create this functionality manually. At the end of my .shrc history I have added this:

trap -- 'fc -ln -- 1 >> "$HOME/.sh_history"' EXIT

This ensures that every time I exit the shell that the commands I have entered in that session are not lost in wind.

Now that I have the saving history bit sorted out, I am wanting to import all commands in ~/.sh_history into fc upon logging in so that I can call commands from previous shell sessions.

I realize that it won't be quite as simple as this because I will have to find a way to make sure that I only append new commands to the end of ~.sh_history, but I am confident I can hack it out provided that it is even possible to give a list of commands to fc without executing them.

3
  • Background: sh on FreeBSD is ash, a modified Almquist Shell. It has no HISTFILE.
    – Kusalananda
    Jul 2, 2018 at 6:06
  • A related question is unix.stackexchange.com/questions/137399 .
    – JdeBP
    Jul 2, 2018 at 7:42
  • FreeBSD sh is a fork of ash, yes, but now it is being developed independently from the original upstream. Also, it does support HISTFILE now. Feb 12, 2022 at 16:14

0

You must log in to answer this question.

Browse other questions tagged .