Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!pacbell.com!att!cbnewsh!wcs From: wcs@cbnewsh.att.com (Bill Stewart 908-949-0705 erebus.att.com!wcs) Newsgroups: comp.unix.wizards Subject: History - Re: dosedit style command edit in UNIX? Message-ID: <1991Apr12.223158.26584@cbnewsh.att.com> Date: 12 Apr 91 22:31:58 GMT References: <1991Apr10.212905.2234@cimcor.mn.org> Organization: News Busters Lines: 82 In article <1991Apr10.212905.2234@cimcor.mn.org> dick@cimcor.mn.org (Dick Schlotfeldt) writes: ] The MS-DOS public domain TSR 'dosedit' keeps a circular ] stack of recently executed commands. The user may retrieve the ] most recent command with a single keystroke (up-arrow), .... ] Is UNIX so sophisticated that no one has been able to implement ] such a simple-minded utility? ] No, no, no, .... not the flames!! :-) If you've been reading the flames here recently, people have been talking about the best ways to do that sort of thing :-). There are half a dozen ways to do it, ranging from minimalist to feature-ridden, slow to fast, messy to clean. One of the nice things about VMS is that this feature is built in (to the command interpreter?) - you just hit the arrow keys to move around your history. One of the braindamaged things is that it knows your terminal looks like a VT100, but that's VMS :-) The original V6 shell and Bourne shell were lean and mean. You could run them on paper terminals where this sort of behaviour just wouldn't do, on machines with 256KB that supported many users. One way they did this was to use "cooked mode" input - the characters you typed were preprocessed by an I/O board or a low-level driver routine before sending them to an application process. Because UNIX systems supported many different kinds of terminals, they couldn't even assume they knew what an up-arrow looked like, because it was different for everyone. The C Shell, which came out about when VMS did, added command history, using an ugly but relatively powerful interface, still cooked mode, with commands to do things like "repeat the last command starting with f". Commands looked about like !f or !!3. Also had aliases and ~user. The Bourne Shell grew in SVR2, adding shell functions (which are more general than aliases), but no history. Somewhere along the way it added built-in echo and test, which made it about as fast as ksh. The Korn shell (YAY!) is twice as big as Bourne Shell; in addition to being upward-compatible and having aliases and ~user, it has two kinds of history interfaces - a command-driven interface similar in character to csh's, and - editor-like interfaces, doing good emulations of vi and emacs. It's MUCH more powerful than the simple dosedit approach, though it's way overkill for lots of applications. The editor avoids knowing about terminal characterics - it sticks to backspace and CR and other vanilla output. It's a bit ugly on a paper terminal, bit still worthwhile. The 'fep' command invented by somebody out in net-land gives you command history for cooked-mode applications by setting up an editor-like program which pre-processes input and sends it via ptys. Of course, most System V systems don't have ptys, and this is pretty hairy. The 9th Edition shell is lean, mean, and clean - On the (10th edition) VAX I sometimes use, sh is 35k, csh ~ 70k, and ksh ~ 95k. SVR2 sh on my 3B2 is ~50k. Command history processing is separate from the shell: - the shell records its history in the file $HISTORY (if set) This means you don't need raw-mode for your shell! - the = command (NOT builtin) is like csh !-history - it executes the most recent command matching a pattern, optionally modified. - the == command is a simple-minded interactive editor, more than powerful enough for command editing (i.e. similar to dosedit or VMS history), but using an interactive style that even works well on paper ttys. - the =p and ==p commands produce stdout instead of executing, which lets you do things from the shell like eval `=p cd` ## ugly, but easy to wrap in a shell function. - All of the =-commands are links to the same 20k program. (Brief digression on why I don't use 9th Edition shell when I'm on their machine - It's mostly that I'm used to ksh, and hadn't bothered to build a shell function for pwd-in-prompt-string and cd - (cd previous-directory). (It was actually much easier to build in V9 sh than SVR2 sh.) It also doesn't have ~user, which is annoying.) -- Pray for peace; Bill # Bill Stewart 908-949-0705 erebus.att.com!wcs AT&T Bell Labs 4M-312 Holmdel NJ # Actually, it's *two* drummers, and we're not marching, we're *dancing*. # But that's the general idea.