7. The Korn Shell
Motivation Prerequisites Objectives Presentation Shell Commands Section 7.1. Introduction Section 7.2. Startup Section 7.3. Variables Section 7.4. Aliases Section 7.5. History Section 7.6. Editing Commands Section 7.7. Arithmetic Section 7.8. Tilde Substitution Section 7.9. Menus: select Section 7.10. Functions Section 7.11. Job Control Section 7.12. Enhancements Section 7.13. Sample Project: junk Section 7.14. Command-Line Options Chapter Review |
MotivationThe Korn shell, originally designed by David Korn, is a powerful superset of the original UNIX Bourne shell, and offers improvements in job control, command-line editing, and programming features. It is very popular in UNIX environments and is available on most Linux systems. |
PrerequisitesYou should already have read Chapter 5, "The Linux Shells." |
Objectives
In this chapter, I explain and
|
PresentationThe information in this section is presented in the form of several sample Linux command sessions. |
Shell CommandsThis section introduces the following shell commands, listed in alphabetical order:
|
7.1. IntroductionThe Korn shell is available for Linux as the Public Domain Korn Shell (pdksh), a public domain reimplementation that is intended to be a clone of the UNIX ksh. Although sometimes not installed in the default set of Linux packages, pdksh is included in most Linux distributions. Another Linux shell, the Z shell (zsh, written by Paul Falstad), also implements most features of the Korn shell, but does not claim complete compatibility with the original Korn shell. The Korn shell supports all of the shell facilities described in Chapter 5, "The Linux Shells," as well as the control structures and conditional expressions described in Chapter 6, "The Bourne Again Shell." The following features unique to the Korn shell are discussed in this chapter:
|
7.2. Startup
The Korn shell is a regular C program whose executable file is stored as "/bin/ksh." If your
When a Korn shell is invoked, the startup sequence is different for interactive
Figure 7-1. Korn shell startup sequence.
The value $ENV is usually set to $HOME/.
TERM=xterm; export TERM # my terminal type. ENV=~/.kshrc; export ENV # environment filename. HISTSIZE=100; export HISTSIZE # remember 100 commands. MAILCHECK=60; export MAILCHECK # seconds between checks. set -o ignoreeof # don't let Control-D log me out. set -o trackall # speed up file searches. stty erase '^H' # set backspace character. tset # set terminal. Some of these commands won't mean much to you right now, but their meaning will become clear as the chapter progresses. Here's an example of a Korn shell ".kshrc" script, which typically contains useful Korn-shell specific information required by all shells, including those that are created purely to execute scripts:
PATH='.:~/bin:/bin:/usr/bin:/usr/local/bin'
PS1='! $ ';export PS1 # put command number in prompt.
alias h="fc -l" # set up useful aliases.
alias ll="ls -l"
alias rm="rm -i"
alias cd="cdx"
alias up="cdx .."
alias dir="/bin/ls"
alias ls="ls -aF"
alias env="printenvsort"
# function to display path and directory when moving
function cdx
{
if 'cd' "$@"
then
echo $PWD
ls -aF
fi
}
Every Korn shell executes this script when it begins, including all subshells. |