wcs@ho95b.UUCP (Bill Stewart) (11/16/84)
> > My impression is that the Korn shell is not generally available > > outside AT&T. Meanwhile, various ksh-like features have been > > appearing in the official Bourne shell. At BRL, Ron Natalie has > I'm intrigued. Could somebody in the know please post a brief > description of ksh? What makes it so much better than csh (or > sh, for that matter)? Is it easier to program? More convenient > for command-line operations? What? > Ray Lubinsky University of Virginia, Dept. of Computer Science Here's a brief description of ksh, from the perspective of someone who likes the convenience of the user interface, but hasn't taken the time to learn all the features that it provides. ksh was written by David Korn at AT&T Bell Labs, Murray Hill. It is (almost) totally upward compatible from /bin/sh (the Bourne Shell). This means that /bin/sh scripts that used to work still work, and you don't have to relearn everything like you would if you switch to csh. The two features that I most like about ksh are history and command-line editing, and these features work very well together. Some of the other extensions include aliases and functions, builtin functions for printing and testing (which make typical shell programs 25% faster), builtin arithmetic. Command-line editing and history: Imagine a file containing all the commands you've typed since you logged on. You are in your favorite visual editor (well, vi or emacs,anyway) at the last line of the file. You can type in a long command, and use the standard editing commands from your editor to modify it as you type. If you want to run a command similar to one you've done before, you use the visual editing commands to move back into the file, find the line you want, edit and modify it, then run it. This lets you: Correct the command you're typing now. Correct a previous command you typed. Do a series of commands to a file, edit the file, and do them again, or do them to a different file. Do a searching-type command (e.g. grep or ls) to a bunch ot files, then do more specific commands to the "interesting" ones. All of these things use the same commands that your visual editor does. The vi-mode puts you in input mode until you type ESCAPE. If you don't type in any editing commands, everything looks like regular shell. This means even your supervisor (who doesn't use the computer much) can use it, and can learn the more powerful features gradually. The history mechanism can be invoked two ways, either by the visual editing modes described above, or by the builtin file control commands.. The file control commands allow you to redo the last command (or the last command matching a give pattern), possibly modified a bit. I tend to use the visual editing for complex changes, and the file control for simple ones. Here are some examples: r <- redo the last command r stuff <- redo the last command starting with "stuff" r < foo | lpr & <- redo the command, in the background, with a different input file, and send it to the printer. These commands are very useful when you want to run a status command (eg for a spooler) or a resource measuring command, then do some stuff, then run the status command again. They're also good when you type a complex command, it dies from simple-to-fix causes (wrong permissions, etc.), and you want to run it again. Footnote - the two things that aren't compatible with /bin/sh are: ^ is no longer supported as a synonym for |. This is a holdover from the Model 33 Teletype, which didn't have a | character. Unfortunately, some shell scripts still contain '^'s, so they need fixing. ~ now means about what it does in csh: ~user means "user's login directory", and ~ means $HOME. This occasionally breaks uucp-related shell scripts, since ~ is a magic character for uucp commands. -- Bill Stewart AT&T Bell Labs, Holmdel NJ 1-201-949-0705 ...!ihnp4!ho95b!wcs