Command-Line Editing

By now you might be wondering how you can go back and re-execute commands you’ve typed earlier without retyping them. The Bourne shell does not allow command-line editing, but the Korn shell does. In this section, I’ll describe how to use command-line editing, but we need to set up a few variables in the Korn shell before we proceed.

Set your default editor to be the vi editor as follows:

VISUAL=vi <cr> 

If the VISUAL variable is not set, the shell will look at the EDITOR variable. You can set the EDITOR variable as follows:

EDITOR=vi; export EDITOR <cr> 

Now you have vi editor commands available to you as you type commands. See Chapter 2, “Using Solaris Editors,” for a complete discussion on the vi editor. While you are typing in commands at the shell prompt, you are actually in the input mode of the vi editor. If you discover an error before you press Return, you can press ESCAPE to switch to the vi command mode. You can then use any vi command to edit the command line. After pressing the Esc key (to get into command mode), you can use the cursor-positioning keys (arrows or h, j, k, l) to move around on the command line. You can search forward (/) and backward (?) using the vi search commands to find commands that have been previously entered. You can modify the command line using one of the many vi command-mode editing commands such as x (delete) or r (replace). To change to input mode while editing the command line, use i (insert), a (append), or r (replace). After you’re finished modifying the command line, press the Return key from anywhere on the line, and the command will be executed.

As you edit the command line, you’ll see one line at a time, as if you are in a line editor. If, however, you want a full vi screen, press Esc and then v. The Korn shell will open the full-screen editor just as if your were in vi. When you save and terminate your vi session using ZZ, the Korn shell executes the command (or commands) that you’ve placed in the work buffer. Create a single line or several hundred lines of commands to be executed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset