Enabling command history

I noticed that the FriendlyWrt image from FriendlyElec has command history enabled even after a reboot, when I typed "history" all the command history was still there. How do I achieve the same thing in the official OpenWrt image?
Thanks

One way is to use bash shell instead of ash, and then use bash as the default shell, or use zsh for more features

opkg install bash
1 Like

Shell history is a compile time option for busybox ash (and changing busybox options is guarded behind developer/ expert options, as this can be rather dangerous).

bash isn't really suited to be used as login shell, for two reasons:

  • it's really slow on low-end devices (e.g. ath79 and similar)
  • it causes a problem for sysupgrade, as bash won't be part of the new upgrade image (unless you use imagbuilder or asu), this means you won't have a valid shell after the sysupgrade and can't login anymore
2 Likes

You can achive it by compiling a personal image from sources, so that you can enable the necessary compile options for busybox.

I do that.

But I do not want to write to flash, so I only use /tmp RAM for storing the history. (But history survives the to the next normal login sessions if the router is not rebooted.)

Necessary changes (2 compile options for busybox, a profile add-on to define history file in /tmp):

.config at the buildhost:

CONFIG_BUSYBOX_CUSTOM=y
CONFIG_BUSYBOX_CONFIG_FEATURE_EDITING_SAVEHISTORY=y
CONFIG_BUSYBOX_CONFIG_FEATURE_EDITING_SAVE_ON_EXIT=y

profile in router:

root@router5:~# cat /etc/profile.d/busybox-history-file.sh
export HISTFILE=/tmp/.busybox_ash_history
3 Likes