Module 50 fc (ksh) (csh)

Previous Table of Contents Next


Module 50
fc (ksh) / ! (csh)

DESCRIPTION

The internal fc command provides access to your history file. The Korn shell creates a history file containing the commands you have previously entered during your current login session. You use the fc utility to:

   Display the contents of the history file.
   Edit (Visually) the contents of the history file.
   Reexecute previous commands stored in the history file.

C Shell
The csh supports history file manipulation with different syntax and functionality. There is no command like fc in csh ; instead, a character is used to access the history file. The default character is an exclamation mark (!). You can reset this using the histchar variable. Unlike the fc command in the Korn shell the C shell does not support visual editing of the history file.

COMMAND FORMAT

Following is the general format of the fc command.

 fc      [ -e editor ] [ -lnr ] [ first [ last ] ]      fc -e - [ old=new ]   [ command ] 

history is an alias for fc -l .

r is an alias for fc -e - . The r command is called the repeat command. It searches for a string in the history file that matches the given argument and then executes the entire line in which the string was found.


C Shell
!reference_string
^l^r[^]
The ! mark signals the shell that you wish to reexecute a command from the history file. The reference_string is composed of three parts . They are the event separator, word designator, and modifiers. These are described in the following sections. The command lines stored in the history file are often referred to as events .
The second format is referred to as Quick Substitution . It is equivalent to the history substitution command,
!:s^l^r[^]
which substitutes string l with string r on the previous command line and executes the new line if the substitution was successful.

Options

The following list describes the options and their arguments that may be used to control how fc functions.

First format
-e editor Use editor editor to edit the commands in the history file. The editing of the history file is referred to as in-line command editing. If you do not specify the -e option, fc checks the value of the FCEDIT variable for an editor name . If FCEDIT is not defined then /bin/ed is used. Valid editors are vi , emacs , gmacs , and ed .
-l List the contents of the history file.
-n Suppress the command numbers when displaying the commands from the history file.
-r Reverse the order of the commands in the history file when they are listed.
- first Beginning command. The number of lines to go back from the last command to start listing out the history file. For example,
 fc -l -25                       history -25 
lists the last 25 commands saved in the history file.
- last Ending command. The number of lines to go back from the last command to end listing out the history file. For example,
 fc -l -n -25 -5                       history -n -25 -5 
lists out the last commands starting 25 commands ago down to 5 commands ago without command numbers.
Second Format
-e - Reexecutes the previous command in the history file. If you do not specify a command or partial command, then the last command you executed is re- executed. This command is the r alias ( alias r="fc -e -" ).

Arguments

The following list describes the arguments that may be passed to the fc command.

First Format
first List commands starting at line first in the history file. For instance,
 fc -l 15                       history 15 
displays the commands beginning at line 15 to the end of the history file.
last List commands up to line last in the history file. For example,
 fc -l 20 30                       history 20 30 
displays lines 20 through 30 of the history file.
Second Format
old=new Substitutes old string for new string in the appropriate command before reexecuting it.
command The command to reexecute from the history file. Command may be one of the following:
   Positive number denoting the event number associated with a command.
   Negative number subtracted from the current command number. The event number of the subtraction is executed.
   A string. The latest command starting with the string is executed. For instance,
 fc -e c 

or
 r c 

searches the history file for the last command that began with a c.
   If no command is specified then the previous command is executed.


Previous Table of Contents Next

Copyright Wordware Publishing, Inc.


Illustrated UNIX System V
Illustrated Unix System V/Bsd
ISBN: 1556221878
EAN: 2147483647
Year: N/A
Pages: 144
Authors: Robert Felps

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