-->
Previous Table of Contents Next


All options given in braces are optional. The -e portion of the command is used to specify the text editor that is to be used for editing the commands in the command history. The first and last options select a range of commands to take out of the history list. First and last can refer either to the number of a command in the history list or to a string that fc tries to find in the history list.

The -n option suppresses command numbers when listing the history commands that match the specified range. The -r option lists the matched commands in reverse order. The -l command lists the matched commands to the screen. In all cases except for the -l option, the matching commands are loaded into a text editor.

The text editor used by fc is found by taking the value of ename if the -e option is used. If this option is not used, fc uses the editor specified by the variable FCEDIT. If this variable does not exist, fc uses the value of the EDITOR variable. Finally, if none of these variables exist, the editor chosen is vi.

If you enter the fc command with no arguments, it loads the last command that was entered into the editor. Remember that when you exit the editor, fc attempts to execute any commands that are in the editor.

The easiest way to understand what the fc command does is to look at a few examples:

fc loads the last command into the default editor.
fc -l lists the last 16 commands that were entered.
fc -l 5 10 lists the commands with the history number between 5 and 10, inclusive.
fc 6 loads history command number 6 into the default editor.
fc mo loads into the default editor the most recent command that starts with the string mo.

Aliases

Another way pdksh makes life easier for you is by supporting command aliases. Command aliases are commands that you can specify and execute. Alias commands are usually abbreviations of other commands.

You tell pdksh to execute a Linux command whenever it encounters the alias. For example, if you have a file in your directory that holds a list of things that you must do each day, and you typically edit the file every morning to update it, you could find yourself entering the following command on a regular basis:


vi things-to-do-today.txt

Because you are entering this command quite often, you may want to create an alias for it to save yourself some typing. So instead of typing this command every time you want to edit the file, you can create an alias called ttd that causes the longer command to be executed.

To set up an alias such as this, use the pdksh alias command. To create the ttd alias, enter the following command at the pdksh command prompt:


alias ttd=’vi things-to-do-today.txt’

From the time that you enter the alias command until the time you exit from pdksh, the ttd command causes the longer command to be executed. If you decide after you enter an alias that you no longer want that alias, you can use the pdksh unalias command to delete the alias:


unalias ttd

After you use the unalias command to remove an alias, the alias no longer exists and trying to execute it causes pdksh to display Command not found.

The following are some aliases that you may want to define:

alias ll=’ls -l’
alias log=’logout’
alias ls=’ls -F’

If you are a DOS user and you prefer to use DOS file commands, you may also want to define the following aliases:

alias dir=’ls’
alias copy=’cp’
alias rename=’mv’
alias md=’mkdir’
alias rd=’rmdir’


Note:  
When defining aliases, there can be no spaces on either side of the equal sign. The quotation marks are only necessary if the command within them contains spaces or other special characters.

If you enter the alias command without any arguments, it prints all of the aliases that are already defined to the screen. There is a way to make sure that all of your alias commands get executed each time you start pdksh. This is done by using an initialization file, which we will discuss later in this chapter in the “Customizing pdksh” section.

Input Redirection

Input redirection is used to change the source of input for a command. Typically, when a command is entered in pdksh, the command expects some kind of input in order to do its job. Some of the simpler commands must get all of the information that they need passed to them on the command line. The rm command, for example, requires you to tell it on the command line which files you want to delete; if you do not specify any files, it issues a prompt telling you to enter rm -h for help.

Other commands require more elaborate input than a simple directory name. The input for these commands is typically found in a file. For example, the wc (word count) command counts the number of characters, words, and lines in the input that was given to it. If you enter the wc command with a filename as an argument, wc returns the number of characters, words, and lines that are contained in that file. An example of this is:


wc test

11 2 1

Another way to accomplish passing the contents of the test file to wc as input is to change (or redirect) the input of the wc command from the terminal to the test file. This results in the same output. The < character is used by pdksh to redirect the input to the current command from the file following the character. So, redirecting wc’s input from the terminal to the test file is done by entering the following command:


wc < test

11 2 1

Input redirection is not used too often because most commands that require input from a file have an option to specify a filename on the command line. There are times, however, when you come across a program that does not accept a filename as an input parameter, and yet the input that you want to give to the command exists in a file. Whenever this situation occurs, you can use input redirection to get around the problem.


Previous Table of Contents Next