11.14 More Ways to Do Interactive History Editingtcsh (8.3 ) is a version of csh that provides history editing (among other things). If you don't want to switch to tcsh , you can simulate history editing using redo . If you're using bash or ksh , you probably already know about your shell's editing - but you may not know about its fc command. 11.14.1 In the C Shell: redo
redo
is a C shell script that is run by being
sourced (44.23
)
into the current shell using an alias.
The original version was posted to Usenet in the 1980s, author unknown.
The version shown here was reposted in 1987 by Dave Patterson.
The alias puts you in an ex
open-mode (30.36
)
editing buffer,
a comfortable environment for vi
users.
You can browse through the
previous 22 commands and press RETURN when you want
to execute the current line.
Before executing, you
can edit the commands as you would in vi
.
You can even search
for strings using
To use redo , first install it read-only with no execute permission (22.2 ) , and then create an alias with the script's absolute pathname (14.2 ) to execute it: alias r source ~/.lib/redo When you run the alias, it reads a set of commands from the sourceable script file (10.5 ) . Here's the redo script:
Type 11.14.2 In ksh and bash: fcksh and bash have a built-in command called fc (for "fix command"). It's like redo , but more powerful. We'll cover the basics here; check your shell's manpage or its Nutshell Handbook for details. To see a list of your previous commands, use the option $ To get a shorter list, give fc
the first number or name you want
to list.
For instance, fc can call a UNIX editor (vi , emacs , pico , etc.) to edit one or more of the previous commands. You can name an editor with the -e option each time you use fc , but it's probably easier to store the editor in the FCEDIT shell variable (in your .profile or .bashrc files (2.2 ) ). To edit the commands above, between - , |
|