PreviousNext

Editing Command Lines With the history Command

Sometimes when you are entering interactive commands, you want to recall and reuse a previously entered command. Let us say you list the objects in a CDS directory and then you modify one of the objects. Now you want to list the objects again to verify that your modification took effect. You can use the history command to recall, edit, and reissue a previously used command. The history facility saves only interactive commands. Commands issued from scripts are not saved and cannot be recalled.

The history command takes various arguments depending on what you want to do. Entering history with no arguments lists all the commands (called events) entered during the current invocation of dcecp.

dcecp> history
1 principal create wardr -fullname {Ward Rosenberry} \
-quota unlimited
2 group add users -member wardr
3 organization add consultants -member wardr
4 account create wardr -mypwd mxyptlk -password qwerty \
-group users -organization consultants
5 history
dcecp>

Each history event is independent of previous events. This means if a recalled command used a variable, its current value may not be the same as when it was first entered. The history command itself generates a history event, too.

By default, the history list keeps the 20 most recent commands. You can use the history keep command to lengthen or shorten the history list. For example the following command lengthens the history list to keep the 50 most recent events:

dcecp> history keep 50
dcecp>

You can specify events in various ways. Positive numbers specify events relative to the earliest event in the list. Negative numbers specify events relative to the most recent command. You can also specify an event by typing characters that match all or part of a previous event.

The history facility lets you reuse previous events in many ways. The following discussion covers just a few of the history commands you can use.

· You can execute a previous command without revision using the history redo command:

dcecp> history
1 directory show /.:/printers
2 object create /.:/printers/ascii_printer1
3 object create /.:/printers/ascii_printer2
4 object create /.:/printers/ascii_printer3
5 history
dcecp> history redo directory
directory show /.:/printers
.
. [output omitted]
.
dcecp>

You can save the most typing by entering just the unique first characters of words in a history command. For instance, you can enter the history redo directory command from the previous example as:

dcecp> hi r d
directory show /.:/printers
.
. [output omitted]
.
dcecp>

Other ways to redo commands include !! which recalls the most recent command and !event number to recall a specific event.

· You can revise and re-execute a previous command using the history substitute command. The most common use of this command might be to correct typing mistakes. It's syntax is:

history substitute old new [event number]

If you omit the event number, you'll redo the most recent command. Replace the old part of the recalled command with new information:

dcecp> history
1 directory show /.:/printers
2 object create /.:/printers/ascii_printer1
3 object create /.:/printers/ascii_printer2
4 object create /.:/printers/ascii_printer3
5 directory show /.:/printers
6 history
dcecp> hi s -2 printer3 printer4
object create /.:/printers/ascii_printer4
dcecp>

You can recall and revise the most recent command using the ^old^new syntax familiar to users of the UNIX csh shell as in:

dcecp> ^4^5
object create /.:/printers/ascii_printer5
dcecp>