On my Debian systems, I have always used pdksh as my interactive shell. Originally, command-line history behavior was similar to what I grew up with on platforms like AIX and Solaris.

Recently, since pdksh on Debian is now implemented by mksh, command-line history no longer works like my fingers expect. I am trying to figure out if I can configure mksh to do what I want, or if I have to find another idiom (or another shell).

I use ksh in vi-editing mode (set -o vi and FCEDIT=vi). Quite often, I write short multi-line commands immediately at the command prompt, i.e.

daystrom:/home/pronovic> for i in 1 2 3
> do
>    print $i
> done

These work as expected in mksh. However, command-line history does not.

In all of the kshell implementations that I am familiar with (prior to now), this script would be preserved in the history as a single entry. So, I could hit ESC-k and go back to the front of the for line. Once I got there, I could edit the script in place again, or I could hit ESC-v to edit the script in vi.

In mksh, each line in my script (the for line, the do line, the print line, etc.) ends up as a separate entry in my history. So, ESC-k just takes me to the done line, ESC-k again takes me to the print line, etc.

I am looking for a way to configure mksh so ESC-k takes me to the beginning of my script so I can execute it or edit it again. However, I haven't found a way to do this.

The only discussion I have found is on gmane, which implies that ^O can somehow be used. However, it's not clear to me how that is relevant -- or maybe it's just not relevant in vi-editing mode.

Is it possible to make this work?


mksh maintainer here ;-) though this is not the usual “support forum”…

In mksh, both interactive edit (not ESC+v (vi) / ^Xe (emacs) though) is limited to single lines, as is history, as it is terminated internally by the newline character. This has always been so, even in pdksh.

Apparently, pdksh in Debian was patched somehow, I see it has the ^J newline characters inline. This was a Debian-specific modification I was not aware of. (I do not use the vi editing mode, so I rely on users to request things and occasionally send in a patch; so far, nobody has come forward to maintain it, so it's somewhat orphaned at the moment, but it's popular enough I'm considering rewriting the whole of edit.c to unify the code for both modes, to get rid of the maintenance problem.)

^O is emacs mode only. But maybe we can make it work for vi mode…

To answer your direct question: No, it is not currently possible in mksh. But I can have a look at what Debian did and try to figure out whether we can take it.

Edit 2015-07-05

I had a look at pdksh; this is actually a feature of “simple” history which is impossible to simply (no pun intended) clone in “complex” history, which the former Debian packaging of pdksh simply decided to not enable, unlike many other OSes.

I have implemented the feature completely anew today, delaying actual history writes until the command was fully compiled, which means you may lose some history entries in rare error conditions (I checked, syntax errors do not belong to that category) but multi-line input now works as desired in Emacs and Vi modes, including ESC v / ^Xe and history storing/loading.

  • I'm accepting this answer, because you've addressed my direct question about whether it's possible. – Ken Pronovici May 1 '15 at 14:07
  • If it's possible to build this functionality back into mksh for use in Debian, I would be happy to help in that effort. It looks like the mksh package in Debian is in a ITA state right now (supposedly waiting for adoption), but nothing has changed since last October. I'll ping the prospective maintainer. If necessary, I'll take over the package and maintain it myself. Let me know if you want me to subscribe to miros-discuss@ or start a private conversation. – Ken Pronovici May 1 '15 at 14:08
  • Do not add this to mksh only in Debian. That would be a maintenance nightmare. I can do this upstream, after a check whether it can be done and makes sense. (But I had some thoughts about it, and I'm fairly certain it could.) miros-mksh@ is the mailing list you want, I'd say. – mirabilos May 1 '15 at 15:58
  • Yes, I agree it would be much better to have the change made in the upstream package, as opposed to maintaining a Debian-specific patch. I was simply volunteering to make sure the functionality was available in Debian once it's been implemented. – Ken Pronovici May 1 '15 at 18:17
  • Thanks, but that's not needed. mksh updates are provided regularily in Debian following a master plan. – mirabilos May 1 '15 at 22:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.