Section 7.2. Startup


[Page 246 (continued)]

7.2. Startup

The Korn shell is a regular C program whose executable file is stored as "/bin/ksh." If your chosen shell is "/bin/ksh," an interactive Korn shell is invoked automatically when you log into a Linux system. You may also invoke a Korn shell manually from a script or from a terminal by using the command ksh. ksh has several command-line options that are described at the end of this chapter.

When a Korn shell is invoked, the startup sequence is different for interactive shells and noninteractive shells (Figure 7-1).

Figure 7-1. Korn shell startup sequence.

Step

Shell type

Action

1

interactive only

Execute commands in "/etc/profile" if it exists.

2

interactive only

Execute commands in $HOME/.profile if it exists.

3

both

Execute commands in the file named by $ENV if it exists.



[Page 247]

The value $ENV is usually set to $HOME/.kshrc in the $HOME/.profile script. After reading the startup files, an interactive Korn shell then displays its prompt and awaits user commands. The standard Korn shell prompt is $, although it may be changed by setting the local variable PS1. Here's an example of a Korn shell ".profile" script, which is executed exactly once at the start of every login session:

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="printenv|sort" # 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.




Linux for Programmers and Users
Linux for Programmers and Users
ISBN: 0131857487
EAN: 2147483647
Year: 2007
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net