3

If I use PC-BSD with the default shell (Korn) then Ctrl+r doesn't work. Why won't it work?

Ctrl-r was introduced to search your history in the late 1970s or early 80s and my BSD still can't do it (while Ubuntu can).

Ctrl-r originates with Emacs doesn't it? When? 1975? 1983?

10

Ctrl+R works with ksh in emacs mode (ksh -o emacs or set -o emacs within ksh), and it was most probably the first shell to support it. Only it's not as interactive as in zsh or bash or tcsh's i-search-back widget.

In ksh (both ksh88 and ksh93), you type Ctrl+RtextReturn. And Ctrl+RReturn to search again with the same text.

In vi mode, you can use ? to search backward and n for next search.

That emacs incremental search feature was added to:

  • bash/readline at least since July 1989 as the feature was already mentioned on usenet at that time but probably not from the start as the version of readline shipped with zsh-1.0 didn't have it.
  • zsh since 2.0 in 1991 after the line editor was rewritten and no longer used readline.
  • tcsh in V6.00.03, 10/21/91, but not bound by default (tcsh had other search mechanism on Meta-P for a while before that though).
  • ksh: ksh was most probably the first Unix shell to have an emacs editing mode, written in 1982 by Mike Veach (as well as the vi mode by Pat Sullivan, reusing code that those two had already applied independently to the Bourne shell) at AT&T. ksh was first introduced outside AT&T at the 1983 USENIX conference where those features were described, but was not commercially available until some time after that (1, 2). It's hard to tell if ^R was already there at the time (in any case, it was already there in 1986 and 1985 (see usr/man/man1/ksh.1 ksh85 man page in that Unix V8 tarball at the Unix Heritage Society)), but it's hard to imagine it wasn't as it's an essential feature, especially for a shell, and I'd expect vi mode's ? would also have been there at the time.
7

The Korn shell does support history searches using CtrlR, at least since ksh93 (and perhaps even ksh88), but they don't work quite like bash. First you need to enable Emacs mode:

set -o emacs

(This enables other niceties, such as arrow keys working by default.)

Now if you press CtrlR, the shell will print ^R; type your search, hit Enter, and the shell will show you the closest matching history entry. You can hit Enter again to run it as-is, or edit it.

-1

In the 1970s there was no cursor editable history for shells.

The first shell with integrated cursor editable history was my bsh in 1984 (based on a prototype from 1982). This history implementation uses crontrol-r to redisplay the current commandline.

In 1986, the Korn Shell became a member of the group of shells that implement a fully integrated cursor editable history.

A tcsh version with integrated editor first appeared in 1987.

Bash appeared in 1989.

Ksh by default does not run in emacs mode but rather in gmacs mode.

Note that ksh93 does support searching with control-r even in default mode, it just does not tell you that it is in that mode. If I type:

^R

I get this echoed and then can enter a search string:

^Rali
alias a=b

it finds the alias command in the history.

  • 2
    AFAIK tcsh had a command line editor as far back as 1983 possibly earlier. – Stéphane Chazelas Apr 20 '16 at 13:11
  • 1
    csh and tcsh had a history but no command line editor at that time – schily Apr 20 '16 at 14:10
  • 2
    tcsh's 5.7 man page mentions: Paul Placeway, Ohio State CIS dept., 1983 Added the command line editor. Confirmed on his CV – Stéphane Chazelas Apr 20 '16 at 14:45
  • 1
    Well, in 1987 people asked me whether I could add my command line editor to tcsh. I did not do that because the strcture of the code was really bad, there was no central input routine and so the only way to get the input was to call iotcl(TIOCSTI). If there was an edit at that time already, nobody did ask...Do you have the source code from that time? – schily Apr 20 '16 at 15:13
  • 1
    I just checked his CV and he claims to have written this code between 1983 and 1988. I would assume that this was not available before 1988. – schily Apr 20 '16 at 15:18

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.