Bug 257495 - sh shell does not save history after reboot
Summary: sh shell does not save history after reboot
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords: needs-qa
Depends on:
Blocks:
 
Reported: 2021-07-30 01:13 UTC by bugzeo
Modified: 2021-08-05 17:42 UTC (History)
4 users (show)

See Also:
koobs: maintainer-feedback? (kiboto6933)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bugzeo 2021-07-30 01:13:30 UTC
/bin/sh (default shell for new users), doesn't save history after reboot. However /bin/csh does preserve history.

$ /bin/csh --help
tcsh 6.21.00 (Astron) 2019-05-08 (x86_64-amd-FreeBSD) options wide,nls,dl,al,kan,sm,rh,color,filec
Comment 1 Kubilay Kocak freebsd_committer freebsd_triage 2021-07-30 01:25:43 UTC
@Reporter Could you:

 - Clarify, is history saved, but then cleared on reboot, or is history never saved? If not, what and how is a reboot a contributing factor?
 - Provide minimal steps to reproduce, with expected and actual behaviour described
 - Provide uname -a output
Comment 2 bugzeo 2021-07-30 02:33:50 UTC
While I am in the same /bin/sh shell session, I can go up to view previous commands. However if I close the shell with CTRL+D and open another one (same user, not root), there's no history. After reboot no history either.

The command "history" says "command not found" in sh, but in csh does exist and throws all the commands from previous sessions.

$ uname -a
FreeBSD freebsd 13.0-RELEASE-p3 FreeBSD 13.0-RELEASE-p3 #0: Tue Jun 29 19:46:20 UTC 2021     root@amd64-builder.daemonology.net:/usr/obj/usr/src/amd64.amd64/sys/GENERIC  amd64
Comment 3 Andriy Gapon freebsd_committer 2021-07-30 06:30:59 UTC
(In reply to bugzeo from comment #0)
Not all shells have a history file support.
FreeBSD /bin/sh is one that didn't use to have it.
Comment 4 Graham Perrin 2021-07-30 07:36:18 UTC
(In reply to Andriy Gapon from comment #3)

Similarly, <https://forums.FreeBSD.org/threads/81237/post-522050>

> … The sh shell does not use a .history file, …
Comment 5 bugzeo 2021-07-30 20:26:12 UTC
So is working as intended. sh does not support history on file. If you want to save history, use another shell.
Comment 6 Piotr Pawel Stefaniak freebsd_committer 2021-08-05 16:15:00 UTC
It does in main, since 988b1bb0c54e.
Comment 7 Mark Millard 2021-08-05 17:42:02 UTC
(In reply to Piotr Pawel Stefaniak from comment #6)

That commit reports:

QUOTE
sh: implement persistent history storage
Implement persistent history storage:
the strategy is simple at start: loads the existing .sh_history file
at exit dump it.
. . .
END QUOTE

Does the shell in which something like a "shutdown -r now"
is typed cleanly "exit" so that the .sh_history file (or
other file if controlled) is reliably updated? What about
other shell's for possibly other logged-in accounts at the
time of such a reboot?

I'm not so sure that this bugzilla entry should be in the
"closed FIXED" state, even for main [So: 14].