📄 unx12.htm
字号:
[122] cd /usr/home/jim/src/payapp/pay001
[123] vi main.c
[124] cc -I../include -o main main.c
[125] fgrep include *.c | grep '^#'
[126] vi checkwrite.c checkfile.c checkedit.c
[127] lint -I../include checkfile.c >errs; vi errs
[128] vi checkfile.c
[129] cc -I../include -o checks check*.c
[130] cp checks /usr/home/jim/bin</PRE>
<HR ALIGN=CENTER>
<NOTE>
<IMG SRC="note.gif" WIDTH = 35 HEIGHT = 35><B>NOTE:</B> The history command is actually an alias for the fc command—specifically, for fc -l.
<BR></NOTE>
<HR ALIGN=CENTER>
<P>The complete syntax for the history command is
<BR></P>
<PRE>history [first] [last]</PRE>
<P>For first, specify the first line to be displayed. You can designate a specific line directly by its line number—for example, history 35—or as a number of lines back from the current line—for example, history -10. You can also give the
command name of the line from which the display should begin—for example, history vi. The Korn shell looks backward from the current line until it finds a command beginning with vi and then displays lines from that point forward.
<BR></P>
<P>For last, specify the last line to be displayed. If you omit last, history lines are displayed from first up to the current—most recently entered—line in the command history. You can use an actual line number, a relative line number, or a
command name to designate the last line to be displayed.
<BR></P>
<P>If you omit both first and last, the Korn shell lists the last sixteen lines of history.
<BR></P>
<HR ALIGN=CENTER>
<NOTE>
<IMG SRC="imp.gif" WIDTH = 68 HEIGHT = 35><B>TIP:</B> You won't know what line numbers to use until you first list some history. Most people begin a search of command history without any operands. If you want to see more lines before line number 160, you
might want to try history 140.
<BR></NOTE>
<HR ALIGN=CENTER>
<H4 ALIGN="CENTER">
<CENTER><A ID="I19" NAME="I19">
<FONT SIZE=3><B>Reexecuting a Command from the History</B>
<BR></FONT></A></CENTER></H4>
<P>The r command enables you to reexecute a command from the command history list. The r command itself isn't added to the history, but the command you reuse is added.
<BR></P>
<HR ALIGN=CENTER>
<NOTE>
<IMG SRC="note.gif" WIDTH = 35 HEIGHT = 35><B>NOTE:</B> The r command is actually a preset alias for the fc command—specifically, for fc -e -.
<BR></NOTE>
<HR ALIGN=CENTER>
<P>The general syntax for r is
<BR></P>
<PRE>r [ old=new ] [ line ]</PRE>
<P>If you omit line, the most recently entered command is reexecuted.
<BR></P>
<P>Specify a line number (25), a relative line number (-8), or a command name (vi) for line to designate the command that you want to reuse. As with the history command, if you specify a command name, the most recently entered command with that name is
reused.
<BR></P>
<P>You can modify a word or phrase of the reused command using the syntax old=new. For example, if the command history contained the following line
<BR></P>
<PRE>135 find /usr -type f -name payroll -print</PRE>
<P>you could reuse the find command, changing only the filename payroll to vendors, like this:
<BR></P>
<PRE>$ r payroll=vendors find</PRE>
<P>The r command echoes the line that will be executed, showing any changes that might have been made. For example, the r command above will yield the following output:
<BR></P>
<PRE>$ r payroll=vendors find
find /usr -type f -name vendors -print</PRE>
<H4 ALIGN="CENTER">
<CENTER><A ID="I20" NAME="I20">
<FONT SIZE=3><B>Accessing the History List </B><B><I>fc</I></B>
<BR></FONT></A></CENTER></H4>
<P>The fc (fix command) command is a built-in Korn shell command. It provides access to the command history list. Forms of the fc command enable you to display, edit, and reuse commands you previously entered. The Korn shell automatically defines the alias
names history and r for you to reduce the amount of typing needed to perform simple history functions.
<BR></P>
<P>The syntax of the fc command is
<BR></P>
<PRE>fc [ -e editor ] [ -nlr ] [ <I>first</I> ] [ <I>last</I> ]</PRE>
<P>Invoked with no options, the fc command selects a line from the command history using the values of <I>first</I> and <I>last</I>, invokes the default command editor, and waits for you to edit the command or commands selected. When you exit the
editor—either by filing the altered command text or by quitting the editor—the commands are executed.
<BR></P>
<P>The fc command actually copies the selected commands into a temporary file and passes the file to the text editor. The contents of the file after editing become the command or commands to be executed.
<BR></P>
<P>For example, if you enter the command
<BR></P>
<PRE>$ fc vi</PRE>
<P>where vi represents the value of first, the Korn shell copies the most recent vi command into a temporary file. The temporary file will have an unrecognizable name, such as /usr/tmp/fc13159, and is located in a directory designated for temporary files.
The file that you actually edit is /usr/tmp/fc13159. Regardless of whether you change the text in file /msr/tmp/fc13159, the Korn shell executes its contents immediately after you exit the editor.
<BR></P>
<P>You can specify the command or commands to be processed in the following manner:
<BR></P>
<P>To process the command that you most recently entered—other than fc, of course—omit both first and last.
<BR></P>
<P>To select and process only one command, specify the command as the value of first and omit last.
<BR></P>
<P>To select a range of commands, specify the first command in the range with first and specify the last command in the range with last.
<BR></P>
<P>To designate a command by its line number position in the history list, use a plain number—for example, 219.
<BR></P>
<P>To designate a command preceding the most recent command in the history list, use a negative number. For example, in the command history list
<BR></P>
<PRE>135 mkdir paywork
<BR>136 mv paymast/newemps paywork
<BR>137 cd paywork
<BR>138 vi newemps
<BR>139 payedit newemps</PRE>
<P>the command fc -2 selects the vi command.
<BR></P>
<P>To select a command by its name rather than by its position in the history list, use a command name or any prefix of a command name. The most recent command line that begins with the string that you specify will be selected. In the previous command
history example, you could also select the <B>vi</B> command by entering <B>fc vi</B>.
<BR></P>
<P>The <I>first</I> and <I>last</I> command line selectors don't have to use the same formats. For example, you could select line 145 of the history list through the fifth-to-the-last line by entering fc 145 -5.
<BR></P>
<P>By default the fc command invokes a text editor on the selected lines and reexecutes them after editing. You can modify this default behavior with the following options:
<BR></P>
<TABLE BORDER>
<TR>
<TD>
<P>-e</P>
<TD>
<P>Use the -e option to override the Korn shell's default editor. For example, to use the vi editor to modify and reuse commands, type <B>fc -e vi .... Use fc </B><B>-e vi ...</B> to override the default editor.</P>
<TR>
<TD>
<P><BR></P>
<TD>
<P>The special format -e - means to suppress the use of an editor. The selected lines are executed immediately with no opportunity to change them. This form of the fc command—as in fc -e - 135—is equivalent to the r command. When you use this
form, the second dash must be a word by itself. The command fc -e - 135 immediately reexecutes line 135 of the command history, while the command fc -e -135 attempts to edit the most recent command in the history list with an editor named -135, which
probably doesn't exist. Alternatively, the command fc -e- 135 generates another kind of error, for -e- isn't a valid option of the fc command.</P>
<TR>
<TD>
<P>-l</P>
<TD>
<P>List: The selected lines are listed. No editor is invoked, and the lines are not reexecuted. The command fc -l is equivalent to the alias history.</P>
<TR>
<TD>
<P>-n</P>
<TD>
<P>Numbers: Use the -n option to suppress the printing of line numbers in front of the command history. The -n option is meaningful only in combination with the -l option—for example, fc -nl.</P>
<TR>
<TD>
<P>-r</P>
<TD>
<P>Reverse: The -r option causes the command history to be printed in reverse order. The most recently entered command is shown first, and successive lines show progressively older commands. Use the -r option in combination with the -l option—for
example, fc -lr.</P></TABLE>
<H3 ALIGN="CENTER">
<CENTER><A ID="I21" NAME="I21">
<FONT SIZE=4><B>Command Editing</B>
<BR></FONT></A></CENTER></H3>
<P>Command editing is arguably the most important extension of the Bourne shell included in the Korn shell. It is a great time-saver, and it makes the shell much easier to use for UNIX beginners.
<BR></P>
<P>The basic idea underlying command editing is to enable you to use common keys occurring on most terminal keyboards to correct keying errors as you enter a command.
<BR></P>
<P>To bring this basic idea to reality, the Korn shell must have some support from the terminal you're using. For example, if you're going to backspace and retype a character, it would be helpful if the terminal is capable of backspacing, erasing a
character already displayed, and typing a new character in its place. For this reason, command editing is most useful with video display terminals. Hard-copy terminals such as teletypes are inappropriate for use with the command editing feature of the Korn
shell.
<BR></P>
<P>The Korn shell supports two distinct styles of command editing: the vi edit mode—named after the vi text editor—and the EMACS editing mode—named after EMACS. If you're already familiar with either of these editors, you can begin to use
command editing immediately.
<BR></P>
<H4 ALIGN="CENTER">
<CENTER><A ID="I22" NAME="I22">
<FONT SIZE=3><B>Activating Command Editing Mode</B>
<BR></FONT></A></CENTER></H4>
<P>Before you can use command editing, you first must activate it. Until you do so, the Korn shell command line works much the same as the Bourne shell. That is, everything you type goes into the command line indiscriminately as text, including control and
function keys. This is a compatibility feature that you'll want to disable as soon as possible—typically, by activating command editing in your login profile.
<BR></P>
<P>To enable the vi editing mode, enter the following command line or place it in your $.profile (see "Customizing" later in this chapter):
<BR></P>
<PRE>set -o vi</PRE>
<P>To enable the EMACS editing mode, enter the following command line or place it in your profile:
<BR></P>
<PRE>set -o EMACS</PRE>
<P>If you're not familiar with either the vi or EMACS text editors but want to use command editing, read through the following sections and choose the editing interface that you find most natural.
<BR></P>
<P><A HREF="unx11.htm"><IMG SRC="bluprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A>
<A HREF="index.htm"><IMG SRC="blutoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A>
<A HREF="unx12s2.htm">[To Chapter 12 Section 2]</A>
<A HREF="index.htm"><IMG SRC="bluprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Home"></A>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -