Android - How to write android shell history to file

mksh developer here.

We disabled persistent history for mksh on Android, in order to not tax the flash memory with too many write requests.

You can re-enable it in a custom ROM by setting -DHAVE_PERSISTENT_HISTORY=1 in LOCAL_CFLAGS in Android.mk. You can also recompile mksh like that and copy that onto your ROM, if it’s rooted and the base OS version is the same.

Furthermore, you can copy any statically-linked binary for the same architecture on the phone and use that. The mksh-static binaries in the Debian package, however, also exclude persistent history.

If you really think this feature is worthwhile, persuade Google to enable it; for that, they need to edit mkmf.sh and remove the following lines…

# even the idea of persistent history on a phone is funny
HAVE_PERSISTENT_HISTORY=0; export HAVE_PERSISTENT_HISTORY

… then rebuild Android.mk from it (which they do for every new version anyway).

Oh, and you could ask the Terminal Emulator for Android developer to bundle a version of mksh with history enabled. This is probably no bad idea anyway, as it’ll be newer than what you get in the stock ROMs, and it won’t overwrite the system shell /system/bin/sh, but be available to CLI users.

That all still won’t enable persistent history by default (I’m strictly opposed to it, as it’s a surveillance feature), but enables users to set $HISTFILE themselves to enable it.