|Previous||Table of Contents||Next|
The syntax for creating aliases for the Korn shell is alias name=value. This creates an alias for the alias command:
$ alias a=alias $
This example aliases the history command to the letter h:
$ a h=history $
The Korn shell comes with a default set of predefined aliases. To display the list, type alias and press Return:
$ alias autoload=typeset -fu false=let Ø functions=typeset -f hash=alias -t - history=fc -l integer=typeset -i nohup=nohup r=fc -e - stop=kill -STOP suspend=kill -STOP $$ true=: type=whence -v $
The default aliases are described in Table 8-3.
|autoload||typeset -fu||Define an autoloading function.|
|false||let -0||Return a nonzero status. Often used to generate infinite until loops.|
|functions||typeset -f||Display a list of functions.|
|hash||alias -t -||Display a list of tracked aliases.|
|history||fc -l||List commands from the history file.|
|integer||typeset -i||Declare integer variable.|
|nohup||nohup||Keep jobs running even if you log out.|
|r||fc -e -||Execute the previous command again.|
|stop||kill -STOP||Suspend job.|
|suspend||kill -STOP $$||Suspend job.|
|true||:||Return a zero exit status.|
|type||whence -v||Display information about commands.|
You can edit the current command before you execute it using the Korn shell in-line editor. You can choose one of three in-line editors: emacs, gmacs, or vi. The in-line editor is specified using the set -o editor option or by setting either the EDITOR or VISUAL environment variable. This section describes how to use the vi in-line editor to edit commands.
The vi in-line editor is a modified subset of the vi program; it lacks some of the features of vi. The vi in-line editor is automatically in insert mode. You can type commands and execute them by pressing Return without using the vi in-line editor. If you want to edit a command, press Escape to enter command mode. You can move along the command line using the standard cursor movement commands, and use standard vi editing commands to edit the contents of the line. When the command is edited, press Return to execute it, or press Escape to return to input mode.
If you want to edit the command line in a vi file, type v to open a vi file containing the contents of the command line. When you leave vi, the command is executed. Refer to Table 2-1, "Some Basic vi Commands" for a quick-reference table of common vi commands.
The Korn shell stores history commands in a file specified by the HISTFILE variable. If the variable is not set, the files are stored in $HOME/.sh_history. You can specify the number of commands stored using the HISTSIZE variable. If the variable is not set, the most recent 128 commands are saved. When the history list contains the maximum number of commands, as new commands are entered, the oldest commands become unavailable.
To set a different history size, type HISTSIZE=n;export HISTSIZE and press Return. History is set to the number of lines you specify.
In this example, the history size is set to 200:
$ HISTSIZE=2ØØ;export HISTSIZE $
You can set the history temporarily for a shell window or set it "permanently" by entering the command as a line in the user's .profile or .ksh-env file.
You can use two commands to show the commands from the history list: fc and history. Because history is aliased to fc -l as one of the default aliases, you can use the commands interchangeably.
To display the last 16 commands in the history list, type history and press Return. The last 16 commands in the history list are displayed:
$ history 16 pwd 17 ps -el 18 ps -el | grep openwin 19 cd 2Ø more questionnaire 21 su 22 lp /etc/passwd 23 lpstat -t 24 man ksh 25 du 26 maker & 27 tip -24ØØ 5551212 28 alias h=history 29 find / -name ksh -print 3Ø df -k 31 history $
An alternative way to display the same information is to type fc -l and press Return.
The history and fc commands take additional arguments that let you specify a range, display the last n number of commands, and display the commands in reverse order. See the ksh(1) manual page for more information.
To use a command from the history list, type r n to reuse a command by number. This example would reuse command 27:
$ r 27 tip -24ØØ 5551212 (Connection messages are displayed)
To repeat the last command in the history list, type r and press Return.
You can display individual history commands and edit them using the fc command, with this syntax:
fc [-e <editor>] [-r] [<range>]
fc -e - [<old>=<new>] [command]
You use the -e option to specify an editor. If no editor is specified, the FCEDIT environment variable value is used. If no value is set, the default editor is /bin/ed. The -r option reverses the order of the commands, displaying the most recent commands at the top of the list. If no range is given, the last command is edited.
For example, to use vi to edit the last command in a history list, type fc -e vi and press Return. A vi file is created containing the last entry from the history list. When you edit the command and save the changes, the command is executed.
|Previous||Table of Contents||Next|