Fix for the problem with history in sh shell

Hi all,

I have created a small script that tries to work around an issue with saving command history in the FreeBSD sh shell.

The reason I wrote it is that sh is the default shell for root on FreeBSD, and overall it is not bad. However, for me as a user, the most annoying issue is how command history is saved.

Because of some quirks in history handling, when multiple root terminals are open, usually only one of them — the last one closed — gets its history saved properly.

Instead of posting the whole script here, I have put it on GitHub:

https://github.com/kacirekj/freebsd-sh-shell-history
 
Hi all,

I have created a small script that tries to work around an issue with saving command history in the FreeBSD sh shell.

The reason I wrote it is that sh is the default shell for root on FreeBSD, and overall it is not bad. However, for me as a user, the most annoying issue is how command history is saved.

Because of some quirks in history handling, when multiple root terminals are open, usually only one of them — the last one closed — gets its history saved properly.

Instead of posting the whole script here, I have put it on GitHub:

https://github.com/kacirekj/freebsd-sh-shell-history

Awesome!

The history missing the last commands is one of those things that you grind your teeth about but hurry away from since focus is elsewhere.

I made the following changes for running it as normal $USER.

I downloaded the script from github and put it in /home/$USER/bin/ as merge_sh_history.sh (with x flag on)
Edited the paths for the part added to /home/$USER/.shrc

sh:
do_backup_sh_history_file() {
  echo "Sync sh history with backup"
  merge_sh_history.sh /home/$USER/.sh_history /home/$USER/my_sh_history_backup
}
 
trap do_backup_sh_history_file EXIT HUP TERM

/grandpa
 
Back
Top