9.4 Command Line Editing

   

As you saw earlier, previous commands can be reused with the help of the history feature. But the history feature executes commands without any modification. If you want to execute a previous command with some modification, you can use the vi editing features for command editing. If you press the graphics/esck.gif keystroke combination, the last command appears on your command prompt. If you continue pressing graphics/k.gif , you can go back as far as the history supports. To go to the next command, you can press the graphics/j.gif key during this process. If you want to edit a particular command, first bring that command on your command prompt using this procedure and then use graphics/l.gif to move right and graphics/h.gif to move left. As you can see, all of these are vi commands. You can use other vi commands to insert or delete any text on the command line.

Use of vi commands with the command line editing feature is controlled by the EDITOR environment variable. The value of this variable must be set to vi to use vi commands.

Study Break

Practicing POSIX Shell Capabilities

Login with your name and go to directory /usr/bin . Type the partial command ll la and then press the graphics/esc.gif key twice. You will find that the shell does not complete the command. Now use the graphics/escequal.gif keystroke combination and you will see a list similar to that shown here.

  1. landiag

  2. last

  3. lastb

  4. lastcomm

The shell did not complete the command when you pressed the graphics/esc.gif key twice because there are four files that start with the combination la . Now add three more characters to your command, making it ll lastc , and then press graphics/esc.gif twice. This time the shell completes the command.

Use the history command to list the last 10 commands in the history. Try to run the fifth-to-last command using the r command. Press the graphics/esck.gif keystroke combination to bring the last executed command to the command prompt and edit it to run the second-to-last command.


   
Top


HP Certified
HP Certified: HP-UX System Administration
ISBN: 0130183741
EAN: 2147483647
Year: 2000
Pages: 390
Authors: Rafeeq Rehman

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